Reading and then updating a file

This is a discussion on Reading and then updating a file within the C Programming forums, part of the General Programming Boards category; Right I got another problem(dont shoot me ) I want to be able to read a file check to see ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    25

    Reading and then updating a file

    Right I got another problem(dont shoot me )

    I want to be able to read a file check to see if a name is there if it is I want to change the number after it to 1. if the name isnt there I want to add it at the end.

    I also want to have another file which would be checked and then if certain lines arent needed anymore they would be removed.

    I`m not sure how to go about this and I have tried searching the faq but cant find anything suitable.

    any help would be brilliant

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >any help would be brilliant
    Read the file into memory, modify the data however you wish, then write the changed data back to file. Simple. As an alternative you could use tmpfile() from stdio.h as a scratch pad. The code for both is straightforward, so if you know how to do rudimentary work with files you can figure it out.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    25
    I know this sounds stupid but how would I read it into memory.

    I have spent the last 2 years doing opengl and all my C knowledge dribbled away.

    Thanks mate

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I know this sounds stupid but how would I read it into memory.
    An array? A linked list? Any data structure you want?
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21