Thread: Random Access Files

  1. #1

    Post Random Access Files

    I'm in the process of creating a program that maintains a staff details file. I've got all the code that creates a random access file, and I can add entries and sort them in the right order within the file. I have now hit a brick wall when it comes to modifying an existing record within the file. The file contains an int called recordnum to keep track of the records and to give random access, so I know how to get to the record and load it into variables but do not know how to save changes back into the same record position. Any help would be greatly appreciated.

  2. #2
    Registered User
    Join Date
    Aug 2001


    Hi there,
    if file is binary.... if file pointer located record originally, rewind file pointer size of 1 record to replace variables in original position on file....
    fseek(fp, (-1 * sizeof(struct whatever), SEEK_CUR);
    then write in the structure..
    fwrite(&struct_identifier, sizeof(struct whatever), 1, fp);
    should work okay.....
    if you dont get your code so far...
    Last edited by bigtamscot; 08-29-2001 at 08:09 AM.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 08:16 AM
  2. Replies: 3
    Last Post: 09-22-2003, 09:48 PM
  3. question on random file access
    By ygfperson in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2002, 05:21 PM
  4. How to Access a Function from Multiple Files?
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 06-08-2002, 06:24 PM
  5. random access
    By RedRum in forum C++ Programming
    Replies: 4
    Last Post: 06-04-2002, 04:34 PM