Hi!
I have been writing a binary file using the fputc function. Is there a function that offer a 'unfputc' ?
This pseudo-code might help understand what I'm looking for:
Code:
#include <stdio.h>
int main()
{
int i = 0;
FILE *fp;
fp = fopen("teste", "w+b");
for (i = 0; i < 10; i++)
{
fputc('t',fp);
fputc('e',fp);
fputc('s',fp);
fputc('t',fp);
}
/* Code here to remove the last 'test' entry (last 4 bytes of the file) */
fclose(fp);
return 0;
}
I know that I could use fseek(fp, -4, SEEK_CUR); to go 4 bytes back in the stream, however what I want is to actually strip the last 'x' bytes of a file. I know I could use a char* to do all operations and then write to a file, but I have already a large program that writes directly to the file, so I was wondering if there's a way to get around this.