On 14 mayo, 18:18, j...@toerring.de (Jens Thoms Toerring) wrote:
> jcasique.tor...@gmail.com wrote:
> > I trying to create a C promang in an AIX System to read JPG files but
> > when it read just the first 4 bytes when it found a DLE character (^P)
> > doesn't read anymore. I using fread function. Here a few lines:
> > char *sAnv;
> > ....
> > sprintf(file_a, "%s/anverso.jpg", strDir);
> > if ((fImagen = fopen(file_a,"rb")) == NULL)
> > {
> > printf("ERROR: No se pudo abrir el archivo |%s|\n", file_a);
> > continue;
> > }
> > fseek(fImagen, 0, SEEK_END);
> > lLongitud = ftell(fImagen);
> > rewind(fImagen);
>
> This will rather likely work on your system, but it won't
> hurt to take a look at question 19.12 in the C-FAQ.
Thank you I made the change and it work's ok.
>
> > sAnv = (char *) malloc(sizeof(char) * lLongitud);
>
> Better drop the cast, it will only keep the compiler from
> warning you if you forgot to include <stdlib.h> (which in
> turn can lead to nasty problems). You may also consider to
> drop the 'sizeof(char)' since that's always 1 by definition
> (and you use 1 under similar circumstances in the call of
> fread()).
>
> > if (!sAnv)
> > {
> > printf("Problema de memoria. Imagen anverso. Taman?o: (%d)\n",
> > lLongitud);
> > fin(-1);
> > }
> > fread(sAnv, 1, lLongitud, fImagen);
>
> How do you found out that this didn't do what you want? You
> don't test the return value of fread(), so I don't see how
> you determined that "it read just the first 4 bytes". There
> is no obvious reason here why fread() should have stopped
> reading after 4 bytes (unless 'lLongitud' is 4). It defi-
> nitely shouldn't do so just because of any special data in
> the file (like the DLE character).
Well I set a variable with the result of fread something like this
size_t resultado;
...
resultado = fread{sAnv,1,lLongitud,fImagen);
then I print a message with two variables printf("Longitud: (%d)
Le*do (%d)\n",lLongitud,resultado); and are the same values
But when I print the sAnv variable it just have 4 bytes
printf("Bytes le*dos: |%s|\n",sAnv); --> Byte le*dos: | Ï Ó|
Here I put a extract from JPG file
############################# B E G I N
################################################## ################
Ï Ó^PJFIF^A^A^A╚╚
█CP7<F<2PFAFZUP_x╚^┬xnnx§»╣^Ð╚
└^K^H^A9^B╝^A^A^Q ─^Y^A^A^A^A^A^A^A^B^C^D^E
─A^P^B^B^A^B^D^B^H^D^D^E^C^D
^B^C^A^B^Q^C^R!^D^S1AQ^Ð^T"2Raq^┴ÐS^Ê*ß#Bb 3Cr┴*4^┬ó$cs±^E5^UTd
┌^H^A^A?¤^Z─gZ$l
;¤q ^K&^└^┼`└^U ^├ß,DNy3^Ll^V^╔'░^├^█^X^F▄
Ù┐IND^]Xnh@t^Ka^Í^ã¦f^È^ãPGC╝▓3^ER*h^N*^H ^Pv="
Y4%^╔,]X┐^H░:^Ì▓─^ÃaÏ║®d´,DDI{È^
]óã▀^Y^C^B{¨^Y®./
z▀╩FuP^K^Z^GãPA^V^M^╔bK^G╝▓^R^GSRjZ╗^ U.á:^Ð^A^┴ÞD^B^H▒,DDDH^H"Ã
############################### E N D
################################################## ##################
>
> > P.D. Sorry about my english but it doesn't my native
> > language. 
>
> Don't worry, neither is it mine
>
> Best regards, Jens
> --
> \ Jens Thoms Toerring ___ j...@toerring.de
> \__________________________ http://toerring.de