Board index » delphi » TURBO PASCAL 6.0, Help with small program

TURBO PASCAL 6.0, Help with small program

Please help
Look at this data and then look at the program bellow

This program should take this data  from a file ( bc-tags.txt )
     Bostom MA,032,CDN NHD NO BC,West Orange NJ1,1029875243,////,
45555(hfgt)#653
     Bostom MB,032,2CDN NHD NO BC,West Orange NJ2,1029875243,////,
455(hfgt)#653
     Bostom MC,032,33CDN NHD NO BC,West Orange NJ3,10293875243,////,
5455(hfgt)#653
     Bostom MD,032,44CDN NHD NO BC,West Orange NJ4,1029875243,////,
455(hfgt)#653

And convert it to this output file as follows( bc-tags.out )( cut the
last two fields)
     Bostom MA,032,CDN NHD NO BC,West Orange NJ1,1029875243
     Bostom MB,032,2CDN NHD NO BC,West Orange NJ2,1029875243
     Bostom MC,032,33CDN NHD NO BC,West Orange NJ3,10293875243
     Bostom MD,032,44CDN NHD NO BC,West Orange NJ4,1029875243

But instead, I am getting this( it is ignoring the SPACES )
     BostomMA,032,CDNNHDNOBC,WestOrangeNJ1,1029875243
     BostomMB,032,2CDNNHDNOBC,WestOrangeNJ2,1029875243
     BostomMC,032,33CDNNHDNOBC,WestOrangeNJ3,10293875243
     BostomMD,032,44CDNNHDNOBC,WestOrangeNJ4,1029875243

Please help me to figure out why the SPACES don't show on the result
output file.

This is the program, TURBO PASCAL 6.0

uses crt;
var
  inputfile: text;
  outputfile: text;
  ch: char;
  counter,totaltags: integer;

begin
  clrscr;
  totaltags:=0;

  writeln('The INPUT file name is   BC-TAGS.TXT');
  writeln('The OUTPUT file is  BC-TAGS.OUT');

  Assign(inputfile, 'bc-tags.txt');
  reset(inputfile);
  Assign(outputfile, 'bc-tags.out');
  rewrite(outputfile);
  while not seekeof(inputfile) do
  begin
    writeln;
    counter:=0;
    totaltags:=totaltags+1;
    while not seekeoln(inputfile)  do
    begin
      Read(inputfile,ch);
      if ch = ',' then counter := counter+1;
      if counter < 5 then
      begin
        write(outputfile,ch);
        write(ch);
      end
      else
    end;
    writeln(outputfile);
  end;
  close(inputfile);
writeln;
writeln;
writeln;
writeln('The proccess was complited');
writeln;
writeln;
writeln('Hit ENTER to exit');
readln;
end.

Please reply to this e-mail     ji...@nycmetro.com

Thanks Doney

 

Re:TURBO PASCAL 6.0, Help with small program


   Enclosed is a rewrite of your program which makes it (1) work and (2)
much simpler:

program strip_Stuff;
uses CRT;
var InputFile   : Text;
    OutputFile  : Text;
    TotalTags,I : integer;
    S           : String;
begin
  ClrScr; TotalTags := 0; Writeln('The INPUT file name is  
BC_TAGS.TXT');
  Assign(InputFile, 'bc_tags.txt'); Reset(InputFile);
  Assign(OutputFile, 'bc_tags.out'); ReWrite(OutputFile);
  while not EOF(InputFile) do
    begin
      Readln (InputFile,S);                         { Read data line }
      Inc(TotalTags); I := Pos(',////',S);  { find where to truncate }
      Writeln (OutputFile,Copy(S,1,I-1))
    end;
  Writeln('The OUTPUT file is  BC_TAGS.OUT');
  close(InputFile); Close (OutputFile);
Writeln;
Writeln;
Writeln;
Writeln('The process is complete - ',TotalTags,' records converted.');
Writeln;
Writeln;
Writeln('Hit ENTER to exit'); Readln
end.

Quote
> Look at this data and then look at the program below
> This program should take this data  from a file ( bc-tags.txt )
>      Bostom MA,032,CDN NHD NO BC,West Orange NJ1,1029875243,////,
> 45555(hfgt)#653
>      Bostom MB,032,2CDN NHD NO BC,West Orange NJ2,1029875243,////,
> 455(hfgt)#653
>      Bostom MC,032,33CDN NHD NO BC,West Orange NJ3,10293875243,////,
> 5455(hfgt)#653
>      Bostom MD,032,44CDN NHD NO BC,West Orange NJ4,1029875243,////,
> 455(hfgt)#653

> And convert it to this output file as follows( bc-tags.out )( cut the
> last two fields)
>      Bostom MA,032,CDN NHD NO BC,West Orange NJ1,1029875243
>      Bostom MB,032,2CDN NHD NO BC,West Orange NJ2,1029875243
>      Bostom MC,032,33CDN NHD NO BC,West Orange NJ3,10293875243
>      Bostom MD,032,44CDN NHD NO BC,West Orange NJ4,1029875243

> But instead, I am getting this( it is ignoring the SPACES )
>      BostomMA,032,CDNNHDNOBC,WestOrangeNJ1,1029875243
>      BostomMB,032,2CDNNHDNOBC,WestOrangeNJ2,1029875243
>      BostomMC,032,33CDNNHDNOBC,WestOrangeNJ3,10293875243
>      BostomMD,032,44CDNNHDNOBC,WestOrangeNJ4,1029875243

> Please help me to figure out why the SPACES don't show on the result
> output file.

Other Threads