Your use of fseek shows no immediate indication of why you are reading all zeros at your requested offset within the file. However, there is really no way to tell what the problem may be because there is no validation of the success or failure of any of the critical operations up to that point in your code. It is impossible to tell if the failure is due to a failure to open f or if the file contains a sufficient number of bytes to support the offset your request, or whether fseek or fread succeeded or failed at that offset, etc...
To begin to understand where the problem lies, you must validate each of the necessary operations up to the point of printf. At least then you would have some reasonable idea at which point your code is failing before running it through a debugger. (may not)
A good first step to solving your problem (as well as just proper code validation) is to check the return of each function called to insure it succeeds and to further validate the reasonableness of the values, as needed. An example of the minimum validation required would be similar to:
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct data { unsigned char a[16]; char b[20]; } data; int main(int argc, char **argv){ FILE *f = fopen (argv[1], "rb"); data e = { .a = {0}, .b = {0} }; long int size = 0; if (!f) { fprintf (stderr, "error: file open failed '%s'.\n", argv[1]); return 1; } if (fseek (f, 0, SEEK_END)) { fprintf (stderr, "error: fseek SEEK_END failed\n."); return 1; } if ((size = ftell (f)) == -1){ fprintf (stderr, "error: ftell failed to return size of file\n."); return 1; } rewind (f); if ((unsigned long)size < 35929 * sizeof e) { fprintf (stderr, "error: offset exceeds file size '%ld'\n.", size); return 1; } if (fseek (f, 35929 * sizeof e, SEEK_SET)) { fprintf (stderr, "error: fseek SEEK_SET failed\n."); return 1; } if (!fread (&e, sizeof e, 1, f)) { fprintf (stderr, "error: fread failed to read data into 'e'\n."); return 1; } printf("%s\n", e.a); fclose (f); return 0; }
Give it a try and report back with additional information and everyone here is happy to lend any additional help you may require.
fseek(f, 35929 * sizeof(data), SET_SEEK);.fseek(f, 35929, SET_SEEK);I don't think there is any defined constantSET_SEEKmaybe you meant to useSEEK_SET.printfis showing zeros, then maybe that is what is in the file. How do you know they are zeros when you are printing a string?