F
Friedrich Dominicus
I stumbled upon the following code (stripped to the minimum)
#include <stdio.h>
#include <stdlib.h>
int main(void){
char *file_name = "t1.txt";
char ch;
FILE *pf = fopen(file_name, "r+");
fputs("bla", pf);
ungetc('z', pf);
ch = getc(pf);
printf("ch = %c\n", ch);
fclose(pf);
return 0;
}
Now I'm wondering if this is defined behaviour or not, and if it's
defined should there be a problem with the close at the end?
Thanks in advance
Friedrich
#include <stdio.h>
#include <stdlib.h>
int main(void){
char *file_name = "t1.txt";
char ch;
FILE *pf = fopen(file_name, "r+");
fputs("bla", pf);
ungetc('z', pf);
ch = getc(pf);
printf("ch = %c\n", ch);
fclose(pf);
return 0;
}
Now I'm wondering if this is defined behaviour or not, and if it's
defined should there be a problem with the close at the end?
Thanks in advance
Friedrich