Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

translation pascal->c++

Posted on 1997-02-08
1
Medium Priority
?
879 Views
Last Modified: 2012-08-14
Could anyone translate this short Pascal program to a C or C++ program??
I know nothing about pascal, so...
program dds;

type
  trec = packed record
           typ : array[1..  2] of char;
           psd : array[1.. 30] of char;
           fic : array[1..  8] of char;
           num : array[1..  5] of char;
         end;
var
  rec   : trec;
  f1    : file of trec;
  f2    : text;
  psd1  : string;
  psd2  : string;
  pth1  : string;
  pth2  : string;
  i     : integer;
  j     : integer;
begin
  pth1:=paramstr(1);assign(f1,pth1);reset(f1);
  psd1:=paramstr(2);
  i:=length(psd1);
  while not(eof(f1))
    do
    begin
      psd2:='';
      read(f1,rec);
      for j:=1 to i do psd2:=psd2+rec.psd[j];
      if (psd1 = psd2) then writeln(rec.psd);
    end;
  close(f1);
(*  close(f2);*)
end.
0
Comment
Question by:steph020697
1 Comment
 
LVL 3

Accepted Solution

by:
rmichels earned 200 total points
ID: 1161964
Here's a go at the translation.  I did
not compile this, so there may be some typeos

//
// make sure you set structure packing to be 1 byte in compile options or compiler pragma
//
typedef trec
{
char typ[2];
char psd[30];
char fic[ 8]r;
char num[5];
};
 
rec  trec;
FILE *f1;

psd1 : string;
psd2 : string;
pth1 : string;
pth2 : string;
i : integer;
j : integer;

int main(int argc, char *argv[])
{

      //
      // you should check arguments here to avoid protect violations or garbage
      //

      f1 = fopen(argv[1],"rb");

      i:=strlen(psd1);

      while not(eof(f1))
      {       
            //
            // read a record from the file
            //      
            fread(rec, sizeof(trec), 1, f1);

            //
            // if the psd field of rec is equal to the second param, then
            // print it out
            //
            if memcmp(argv[2], rec.psd, i) then printf("%s\n", ref.psd);
      }
      fclose(f1);
}
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question