2 Replies - 422 Views - Last Post: 10 March 2011 - 10:58 AM Rate Topic: -----

#1 Matty919  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 83
  • Joined: 10-May 09

[C] Text file functions

Posted 10 March 2011 - 10:28 AM

If im making a program that peforms lost of functions on a text file such as word count, find and replace etc would it be better open and close the program each time I peform a function or open the file at beginning when the program is run and leave it open? I'm thinking the former.
Is This A Good Question/Topic? 0
  • +

Replies To: [C] Text file functions

#2 Salem_c  Icon User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 1653
  • View blog
  • Posts: 3,131
  • Joined: 30-May 10

Re: [C] Text file functions

Posted 10 March 2011 - 10:34 AM

If you're doing lots of counting, just leave it open.

But if you're modifying the file, then it's usually
- open old file for reading
- open new file for writing
- copy / amend what you want to keep
- close both files
- delete (or rename to .bak) the old file
- rename the new file
Was This Post Helpful? 0
  • +
  • -

#3 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2651
  • View blog
  • Posts: 15,673
  • Joined: 24-September 08

Re: [C] Text file functions

Posted 10 March 2011 - 10:58 AM

You could load the file's contents into an array or list, then close it, do whatever, then write it back out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1