mardi 7 avril 2015

Deleting null character from a file

When writing in a file, I generate several null characters /00 each time a new write operation is performed. Bellow it is my approach to tackle this task, but it does not work.


File content:


foo\00\00\00\00\00\00


Code approach:



int aux;
while((aux = fgetc(fp)) != EOF){
printf("%i\n", aux);
if(fgetc(fp) == '\00'){
fseek(fp, -1, SEEK_SET);
ftruncate(fileno(fp), ftell(fp));
}
}


How should this be done?


Aucun commentaire:

Enregistrer un commentaire