Solved

translation pascal->c++

Posted on 1997-02-08
1
865 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

751 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