-3

I'm trying to manipulate images using c, and trying to fully understand fseek() and fread() mechanisms.

Why fseek did not change the address of point even it affected the fread function but did not change the point address or increase it?

Here is a simple example

int main()
{
    char *x[5]={"axxxx","aaaa","hxxx","rrrrr","xsdsdd"};
    char *point=x;
    char buffer[65]={0};

    fread(buffer,6,1,point);     //Here fread copy "axxx"
    fseek(point,5,SEEK_CUR);    //Here fseek increase point by five bytes
    fread(buffer,6,1,point);   // Here fread do nothing copy nothing
    printf("%s\n",buffer);    // buffer contain "axxx" first fread call
    printf("%x\n",point);    // point address did not changed because of fseek
    printf("%x",x);          //x still the same as point pointer

    return 0;
}
Mathieu
  • 8,840
  • 7
  • 32
  • 45
IDEN
  • 21
  • 1
  • 9

1 Answers1

1

fread should take a FILE * argument for the 4th parameter. You give a "char *".

What do you expect really here ? FILE is an opact structure containing what we call a "position indicator". That's what allows to "move" in the file, fseek and ftell.

Your char * doesn't have that, your code is bugged.

Properly open a file with fopen.

H.S.
  • 11,654
  • 2
  • 15
  • 32
Tom's
  • 2,448
  • 10
  • 22