Q:

Reading a file with fgetc stops unexpectedly

I'm trying to make a program that, given an input image "test.jpg", create a copied image "copy.jpg" in the same folder.
I already written that:
int main()
{
    FILE *file;
    file = fopen("test.jpg", "rb");
    unsigned char d;
    while((d = fgetc(file)) != EOF){
        printf("%u ", d);
    }
    return 0;
}

But it goes in loop printing only 255.

A:

The value of EOF does not fit in an unsigned char (otherwise reading a character of that value could not be distinguished from the end of file). You need to have int d.

