User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 391,592 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,717 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser:
Views: 4361 | Replies: 2
Reply
Join Date: Apr 2005
Posts: 10
Reputation: peachy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
peachy peachy is offline Offline
Newbie Poster

Solution Passing txt files into a programand writeln info out

  #1  
May 13th, 2005
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2005
Location: Georgia, USA
Posts: 8
Reputation: Daaave is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Daaave Daaave is offline Offline
Newbie Poster

Re: Passing txt files into a programand writeln info out

  #2  
May 13th, 2005
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).

procedure CopyFile;
var
  F1  : text;
  F2  : text;
  FN1 : string;
  FN2 : string;
begin
  FN1 := 'infile.txt';
  FN2 := 'outfile.txt';

  assign( F1, FN1 );
  reset( F1 );  { open file for reading }

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

  while not EOF( F1 ) do
  begin
    readln( F1 );
    { file manipulation goes here }
    writeln( F2 );
  end;

  close( F1 );
  close( F2 );
end;
Reply With Quote  
Join Date: Apr 2005
Posts: 10
Reputation: peachy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
peachy peachy is offline Offline
Newbie Poster

Re: Passing txt files into a programand writeln info out

  #3  
May 13th, 2005
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!!!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Pascal and Delphi Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 11:25 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC