I want to write a C program to read a png's pixel values without any external libraries (excluding zlib for decompression). I have studied the Wikipedia page for png's and have seen some python tutorials which do the same.
Currently, I am trying to read the bytes of the png into an array. Currently, I am using this picture which has some black dots that I would use to verify the pixel coordinates in the final array. However, when printing the retrieved array I only get the first four bytes of the png:
ëPNG
I verified that it was not in fact printing the bytes that is the problem when I asked for the sizeof() the array and it returned 4. I don't understand what is wrong with this code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
FILE *fp = fopen(argv[1], "rb");
unsigned char* file_data;
fseek(fp, 0, SEEK_END);
long int length = ftell(fp);
rewind(fp);
file_data = (char *)malloc((length+1)*sizeof(char));
fread(file_data, length, 1, fp);
printf("%s\n", file_data);
printf("%d\n", sizeof(file_data)/sizeof(file_data[0]));
fclose(fp);
return 0;
}