c - I write to a file but the changes doesn't save -


i'm writing function change value in csv file, , vs debugger says it's working perfectly, after program exits, see in file no changes have been made. know why?

int changevalue(int line, int row, char* text, char* fi_le) /*line , row places in value in file , fi_le address file*/ {     int = 1;     char letter = ' ';     file* file = fopen(fi_le, "r+");     if (!(file))//checks file exists     {         printf("file r+ open in changevalue -- error!");         return 1;     }     while (i < line)//first line number 1     {         letter = fgetc(file);         if (letter == '\n')         {             i++;         }     }     = 0;     while (i < row)//first row number 0     {         letter = fgetc(file);         if (letter == ',')         {             i++;         }     }     (i = 0; < strlen(text) - 1; i++)//writes new value in old's value place     {         fputc(text[i], file);     }     fclose(file);     return 0; } 

when file open using + mode, , writes following reads, must preceded call file positioning function.

after read characters file, need call either: fseek, fsetpos, or rewind, functions.

to fix code, store total character count read in file, , call function fseek, second argument count , third seek_set.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -