I can't understand why this little C code doesn't work
#include <stdio.h> main(int argc,char **argv){ FILE *fp, int i; size_t elem_read; int buffer[100]; fp=fopen(argv[1],"r"); elem_read=fread(buffer,sizeof(int),100,fp); for(i=0;i<elem_read;i++) fprintf(stderr,"%d\t",buffer[i]); fclose(fp); } To shorten the code I haven't done any error checking but it should work...I have tried it with both txt and bin file to read numbers and print them out. I think I understand why this doesn't work with txt files, but I dont understand why it doesn't with .bin files? I have a file that contains 4 ints: 10 10 10 10, but when I try to run it with ./a.out file.bin I get some randomg numbers(garbage output), Where's the problem?
10 10 10 10?