-
simple JPEG problem
Igot a simple problem that i've already asked about before
but the answear i got didn't work. I want to open JPEG files
in C and was told to open the file as usual but using binary
like this;
Code:
#include<stdio.h>
main()
{
FILE *ptr;
ptr=fopen("c:\\test.jpeg","rb");
if(ptr==0){
printf("didnt work");
getchar();}
else
fclose(ptr);
return 0;
}
I know its real easy for you wiz's but i havent found anything
that can answear my simple question!!
-
What didn't work? What error are you getting?
-
Add this to your code and see what you get:
Code:
if(ptr==0){
printf("didnt work");
perror("Error");
getchar();}
-
ok
so perror tells me "no such file or directory found" however at the same time i can see
the image file there!!
And the code works fine with a txt file in the same location. I dont see any reason for perror to tell me what its telling me!?!
-
Are you absolutely sure the image file is in the root of C and called exactly what you have in the code? Is the image perhaps called test.jpg, and not .jpeg?
-
thanks cornedBee.
The extension was JPG and not JPEG.
Another of my little problems solved.
Thanks for the help guys. I owe you one:-)
-
It is for this reason I like to use this kind of skeleton.
Code:
#include <stdio.h>
int main(void)
{
static const char filename[] = "c:\\test.jpeg";
FILE *file = fopen( filename, "r" );
if (file != NULL)
{
/* do stuff */
fclose( file );
}
else
{
perror( filename );
}
return 0;
}
/* my output
c:\test.jpeg: No such file or directory
*/