int main(void){ char buffer[5] = {0}; int i; FILE *fp = fopen("haha.txt", "r"); if (fp == NULL) { perror("Failed to open file \"mhaha\""); return EXIT_FAILURE; } for (i = 0; i < 5; i++) { int rc = getc(fp); if (rc == EOF) { fputs("An error occurred while reading the file.\n", stderr); return EXIT_FAILURE; } buffer[i] = rc; } fclose(fp); printf("The bytes read were... %x %x %x %x %x\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]); return EXIT_SUCCESS; }
I put eight 0s in my haha.txt file, and when I run this code it always gives me :
The bytes read were... 30 30 30 30 30
Can someone tell me why?