C fread() on short file is producing junk after the file ends
问题 My professor specified that file_1.txt be read 100 bytes at a time into a char array . I produced the following snippet code : int key; key = atoi(argv[1]); FILE *file_pointer; file_pointer = fopen(argv[2], "rb"); char buffer[100]; char output[sizeof(int)][100]; int output_counter = 0; int read_counter; int read_elements; while(read_elements = fread(buffer, 1, 100, file_pointer) > 0) { read_counter = 0; while(read_counter < 100) { printf("xor'ing %d and %d\n", key, buffer[read_counter]);