H
hstagni
I tried to use fseek in a file opened for writing:
------ BEGIN -------
int main()
{
char c;
FILE *fp;
fp=fopen("texto", "wb");
putc('a', fp);
putc('b', fp);
fseek(fp, -1, SEEK_CUR);
c=getc(fp); printf("%c", c);
fclose(fp);
return 0;
}
------END--------
However, the result of "printf" was the EOF char and I was expecting a
"b".
I know the problem is in fseek, because it doesn´t work(how i wish it
works) on files opened for writing.
THE QUESTION IS:
WHAT SHOULD I DO TO MAKE THE SAMPLE ABOVE WORK?
------ BEGIN -------
int main()
{
char c;
FILE *fp;
fp=fopen("texto", "wb");
putc('a', fp);
putc('b', fp);
fseek(fp, -1, SEEK_CUR);
c=getc(fp); printf("%c", c);
fclose(fp);
return 0;
}
------END--------
However, the result of "printf" was the EOF char and I was expecting a
"b".
I know the problem is in fseek, because it doesn´t work(how i wish it
works) on files opened for writing.
THE QUESTION IS:
WHAT SHOULD I DO TO MAKE THE SAMPLE ABOVE WORK?