Mar 22, 2013 at 3:37pm UTC
Hello I have a question how can i read a png file binary?
FILE *f = fopen("image.png","r");
How to use fread now for example just to printf the numbers from the file?
Mar 22, 2013 at 5:07pm UTC
Oh I forgot to say I am working with standard C not C# or C++
Mar 22, 2013 at 5:29pm UTC
It needs to be opened in binary mode..
Also, you need to understand the structure of the file otherwise everything will look like numbers to the program..
The answer would depend on what exactly you are trying to do.. for some specific tasks libpng can help.
Last edited on Mar 22, 2013 at 5:30pm UTC
Mar 22, 2013 at 5:36pm UTC
I would like to open png file and read its magic numbers to determine if it is a png file. I made a mistake it should be "rb". Now I just don't understand the syntax of a fread.
Mar 22, 2013 at 6:00pm UTC
well yeah I can but I need to make a program :)
Mar 23, 2013 at 10:06am UTC
1) Why does this only go through loop once? The thing I wanna do is read text from table besede which is name of the file and open that file. When the first loop is over i want to open next file.
1 2 3 4 5 6 7 8 9 10 11
int i = 0;
while (i < 6){
unsigned char n[23];
FILE *f = fopen(besede[i],"rb" );
fread(n, sizeof (int ),23,f);
fclose(f);
for (int j = 0; j <= 23; j++){
printf("%d \n" ,n[j]);
}
i++;
}
If I change besede[i] to besede[0] ... it works fine.
2) how do I compare unsigned char table with integer.
Last edited on Mar 23, 2013 at 10:47am UTC
Mar 23, 2013 at 1:18pm UTC
That code could give you a segmentation fault on fread line, you request 23 * sizeof(int) bytes when you only have a 23 bytes buffer.
Mar 23, 2013 at 1:33pm UTC
so how can i change it to work ok + the while loop
Mar 23, 2013 at 2:32pm UTC
I guess that was the problem. I changed the line to fread(n, 1, 23, f); and now the loop works. I still don't know why?