Run this:
Code:
#include <stdio.h>
int main(void) {
int c, i, j, k;
FILE *fp;
if((fp=fopen("test1", "wb")) == NULL) {
printf("Error: unable to open the input file");
return 0;
}
fprintf(fp, "%d %c %d\n",26,'e',35);
printf("Writing two numbers and a letter, to a binary file\n\n1): 26\t2): e\t3): 35\n");
fclose(fp);
//get a word from the text file
printf("\nClosing the file, and reopening it - and reading the data:\n\n");
if((fp=fopen("test1", "rb")) == NULL) {
printf("Error: unable to open the input file");
return 0;
}
fscanf(fp,"%d %c %d",&i,&j,&k);
printf("1): %d\t2): %c\t3): %d\n",i,j,k);
fclose(fp);
printf("\n\n");
return 0;
}
In this case, putc() is producing an error, which puts an error onto the stream, and returns an EOF - but that has nothing to do with 26. That's just what putc() was designed to do.