Solved

translation pascal->c++

Posted on 1997-02-08
1
851 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 100 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now