vendredi 16 janvier 2015

How do I properly move a file pointer in C

I'm messing around with file pointers in C, and my exercise is to write a database (format: ID NAME SURNAME AGE) into a textfile. So everything works fine (saving new data etc.) but I can't find a solution on how to delete a line in my textfile.



void cut_from_file(char* filename, int start, int stop) {
FILE *fp = fopen(filename, "w");
fpos_t position;
fseek(fp, 34, SEEK_SET);
fputs("Hello world", fp);
fclose (fp);
}


Note: I want to make it somehow a random access file.


So my question would be how can I move the filepointer let's say 34 characters forward and overwrite the characters on that position but leave the characters from position 0 - 33 as they are?


If I try to do it like on my test function above I overwrite everything from offset 0 - 33 with '/00' and on position 34 is Hello World.





Aucun commentaire:

Enregistrer un commentaire