Re: opening jpeg file in c++



On Oct 31, 11:04 am, mohi <mohangupt...@xxxxxxxxx> wrote:
hello everyone ,

i am trying to read a jpeg image through c++  but is unable to do so ,
presently i tried it with code in c as i use something like ;

FILE * fp=fopen("./x.jpg","rb");
int c;
do{
fread(fp,&c,sizeof(c));
if( c==(int) 0xFF23){
do.....
do....

}

printf("%x",c);

}

while(c!=EOF);

but the problem is the if condition never evalutes to true as i know
that according to the jpeg standard there should be market with value
0xFFD8 and others also .....and also the printf() of integer 'c' as
hex is never displayed it just displays a blank ..


Make sure you turn on compiler warnings and #include <stdio.h>.
Look up fread, your code above has 3 arguments, fread has 4 and in a
sort of strange order:
size_t fread(void *ptr, size_t size, size_t nmemb, FILE
*stream);

0xFF23 is very likely bigger than an int on your machine, btw.

c will not be set to EOF, look at return status of fread.

You have lots of other issues too, but that should get you started.

-David

.



Relevant Pages

  • Re: im facing problem with fread()??
    ... > Rajshekhar, please quote what you're replying to in your message. ... it tries to read 5*(sizeof int) from the file. ... > been numerous posts to this newsgroup asking the same question you have ... > From the description I have of 'fread', ...
    (comp.lang.c)
  • Re: Printing the last item of a structure twice
    ... feof is not predictive. ... The first time you call fread, teu is populated with data. ...
    (comp.lang.c.moderated)
  • Re: An interesting thing about fread().
    ... int main ... int rdbytes = 0; ... unsigned char buffer; ... Every time I use fread(), I always assume freadcould be reliable. ...
    (comp.lang.c)
  • Re: compiling error
    ... The first argument to fread() is normally the address of an array, ... no cast is required when converting between void * ... then the compiler automatically converts int* to void* before calling ...
    (comp.lang.c)
  • Re: im facing problem with fread()??
    ... if it's a text file use fgetsrather than fread() ... int main ... fit in a 5 bytes array. ... Really do change over to fgets(). ...
    (comp.lang.c)