James Kanze
10/31/2008 8:51:00 PM
On Oct 31, 6:10 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> mohi wrote:
> > 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 ..
> In which system are you running this? If you are running it in
> a unix shell, the prompt might be overwriting what that
> printf() printed because you are not printing a newline
> character at the end.
I rather doubt that he gets that far.
> The most probable reason for the if() to fail is that you are
> probably reading 4 bytes rather than 2 (I will assume in your
> system 'int' is 32-bit), and will have something completely
> different from 0xFF23 even if the first two bytes in the input
> file had those values.
The most probably reason his code even compiles is that he's
working in C, not in C++. It won't compile with any C++
compiler I've ever used.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34