Solved

translation pascal->c++

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

785 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