I want to read files as binary and wrote this piece of code :
`#include <stdio.h>
int main()
{
FILE * fp = fopen("/home/lovelorn/Pictures/post-3.jpeg", "rb");
int n;
for (int i = 0; i < 100; i++)
{
fread(&n, 1, 1, fp);
printf("%dn ", n);
}
fclose(fp);
return 0;
}
`
It’s a JPEG file and must be 255 , 216 , 255 etc But GCC and CLang most of times in compiling , give me some random and garbage values and numbers and when I write fread(&n, 4, 1, fp) it become worse and negative numbers come up . What’s wrong with this piece of code ? TCC always compile it true and give true numbers
As definition of fread is pointer for storing , I pass a variable by its address and I tried to redirect it but I couldn’t and if this is wrong code ; How to read a file as numbers ( binary ) with fread . Thanks