Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

translation pascal->c++

Posted on 1997-02-08
1
Medium Priority
?
876 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

721 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