1

I am trying to get the size of an image file by doing the following

fp = fopen(path,"rb");
fseek(fp,0,SEEK_END);
size = ftell(fp);
fseek(fp,0,SEEK_SET);

The problem is that when I get to the first fseek my program terminates. I have tested with a text files and it works and have seen some other examples online where the same method applies to images.

user1072706
  • 573
  • 2
  • 8
  • 20

1 Answers1

1

you are very closed, just a small difference

FILE *f = fopen("filename", "rb");
long size = 0;

if (f == NULL)
 printf("error"); //handle error
else
{
fseek(f, 0, SEEK_END);
size = ftell(f);
}
Linga
  • 10,379
  • 10
  • 52
  • 104
  • 2
    What is pfile? For simplicity we are assuming fp is not NULL. – user1072706 Feb 12 '13 at 06:16
  • It doesn't make sense - why would you open the file twice in different mode? And error checking should be done on `f`, not `pFile`, since it is what we are going to operate on. – nhahtdh Feb 12 '13 at 06:29