Thread: help, updating file via file pointer

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    31

    help, updating file via file pointer

    Hi, I have this problem of file pointer not updating file, it just keep on writing the old file. For example, I punched in a couple of datas and hit the save file function(writes to a file recording the data), but when I keyed in the new datas and want to save again, the saved content is still the old one not the newly created data.

    I have tried this fptr=fopen("data","w+"), it still does not update the new values into the file. Can anyone please help?

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Can't help much without seeing the code...

    Is it possible that you're writing to another copy of "data" (and looking in the wrong directory)?

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    31
    it just a simple routine actually:

    code:
    Code:
    void save_onto_file(void)
    {
             FILE* fptr;
             int i;
             int temp;
             
             fptr=fopen("file-data","w+");
             if(!fptr)
            {       exit(101);}
            else
             {
                    printf("create a new file\n");
              }
            
            for(i=0;i<=2;i++)
           {   
                   
                   temp=datas[i];
                   
                   fprintf(fptr,"%d %d\n",i,temp);
                
                   
             }

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Maybe you need to close the file at the end of save_onto_file():

    fclose(fptr);

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    31
    I tried that, but strangely it still doesn't solve the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM