When I write out a character with a value of 26 to a file and then read it back in, instead of getting that character back I get an EOF. It is clearly an EOF because that read operation is checked for error at line 23. Also the write operating is checked for error at line 12 so the file has indeed been written to. I have also verified that after this program has been run the file has exactly one character written to it. I can't figure out why I can't read that character back in.
Program Source:
Code:
1:
2: #include <stdio.h>
3:
4: int main()
5: {
6: int ch;
7: FILE *test;
8:
9: if (!(test = fopen("test.txt", "w")))
10: return 1;
11:
12: if (fputc(26, test) != 26)
13: return 3;
14:
15: fclose(test);
16:
17:
18: if (!(test = fopen("test.txt", "r")))
19: return 1;
20:
21: ch = fgetc(test);
22:
23: if (ferror(test))
24: return 2;
25:
26: printf("%d\n", ch);
27: printf("%c\n", (char)ch);
28: fclose(test);
29:
30: return 0;
31: }
32:
Program Output: