I'm facing a problem when trying to read a binary file of fixed size. The code below returns segmentation Fault just before closing the file. What I want to achieve it is to return an int pointer back to the main function.
The file it s a raw grayscale image, which has values from 0 to 255, that's why I'm using unsigned char. 
How can I convert and assign from unsigned char to *int properly?
Any kind of help will be welcome!
void readBinaryFile(char *filename, int *in){
    FILE *file;
    long length;
    unsigned char *imagen;
    int c;
    file = fopen(filename, "rb");
    fseek(file,0,SEEK_END);
    length = ftell(file);
    imagen = (unsigned char *) malloc(length);
    fseek(file, 0, SEEK_SET);
    fread(imagen, length,  1 , file);
    int cont;
    //c+4: file contains values from 0 to 255 
    for(c=0,cont=0;c<length;c=c+4,cont++){
       in[cont] = (unsigned char) imagen[c];         
    }
    for(cont=0;cont<length/4;cont++){
       printf("%d",(int) in[cont]);
    }
    fclose(archivo);
    free(imagen_buffer);
}
void main(int argc, char **argv){
    int *in;           
    int fixed_size = 784;
    in = (int *) malloc((fixed_size)*(fixed_size));
    readBinaryFile("test.raw", in);
    int c;
    for(c=0;c<((fixed_size)*(fixed_size));c++){
        printf("%d", (unsigned char) in[c]);
    }           
}
 
    