Can anyone tell me the format for reading information into a program and if I want to save information out of the prgram into a txt file.

I understand it to be

Assign (file name, path)
reset (filename)
close (file name)

and to write information out

assign (filename, path);
rewrite(filename, with all the information)
close (filename)

Which brings up another question: Is it possible to read the txt file line by line and then save it out to another txt file line by line or must it be done as a entir file?

File I/O line-by-line (for text files) is fairly simple.

Assign associates an external filename with a file variable. This is the first step in file I/O. After the Assign, all references to the file are made through the file variable.

Reset opens a file for reading, preserving the contents and placing the file position at the beginning.

Rewrite opens a file for writing, destroying the contents and placing the file position at the beginning.

For Reset and Rewrite: If the file is an untyped file (i.e. F : file ), an optional record size parameter can be passed to the call (i.e. Reset( F, 256 )). Default record size is 128.

Append is used to open a text file, placing the file position at the end, to allow for the addition of text to the file.

File I/O with typed files is just about the same. Declare a file of a structured type (i.e. F : file of CustRec), then do a Reset. To get to record number N, call Seek( F, N ), where the first record in the file is record 0. In the case of file I/O on untyped files, Seek( F, N ) will seek N records into the file based on the filesize passed when the file was opened.

Be aware that some of this information may be specific to Delphi, but I believe it to be applicable to modern "generic" Pascal compilers. (For instance, Delphi now uses AssignFile to replace Assign, as Assign is now a method call in objects).

[B]procedure[/B] CopyFile;
  F1  : text;
  F2  : text;
  FN1 : [B]string[/B];
  FN2 : [B]string[/B];
  FN1 := 'infile.txt';
  FN2 := 'outfile.txt';

  assign( F1, FN1 );
  reset( F1 );  [I]{ open file for reading }[/I]

  assign( F2, FN2 );
  rewrite( F2 );  [I]{ open file for writing, destroying contents, if any }[/I]

  [B]while not[/B] EOF( F1 ) [B]do[/B]
    readln( F1 );
    [I]{ file manipulation goes here }[/I]
    writeln( F2 );

  close( F1 );
  close( F2 );

Thank you!!!

I am not having a specific problem with it now... But I didn't understand how to do it when i read it in the text.
Thank you!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.