Pregunta

    fseek(fp,pinakas[256]*y,SEEK_SET);
    fread(pinakas,sizeof (pinakas[256]),1,fp);
    for(p=0 ; p<256 ; p++)
            printf(" %d",pinakas[p]);

whats the problem here?because every time i print the same numbers... y is an int which changes value. in fp i open a binary file... and i take this:

-120 36 -83 -5 0 -64 121 -73 0 -64 121 -73 0 -64 121 -73 0 -64 121 -73 0 -64 121 -73 0 -64 121 -73 0 -64 121 -73 0 64 122 -73 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 16 43 9 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 18 43 9 0 0 0 0 0 0 0 0 0 0 0 0 20 18 43 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -128 122 -107 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

i take a logical address and i turn it into physical.then i have to take a 256 byte page from a binary file and store to it physical memory.the "y" here is the page number.so with fseek i try to find the specific page in the binary file and with fread to read it and store it to pinakas[256].

¿Fue útil?

Solución

It is not very clear what you are trying to do, but this is my guess anyway: you are reading blocks of data from a file, each 256 bytes in length:

char pinakas[256]; //this is the memory buffer for one page

int y = ...; //this is the page number
int p;

fseek(fp, 256*y, SEEK_SET);
fread(pinakas, 256, 1, fp);
for (p = 0; p < 256; p++)
    printf(" %d", pinakas[p]);

One error in your code is the use of sizeof: sizeof(pinakas) is 256 (the size of the array), but sizeof(pinakas[256]), or any other number is just 1 (the size of any element of the array).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top