fread/fseek doesn't read data

0 sara v · June 4, 2015
Could you guys help me out with this? I'm trying to read data from the file but whenever I run the program I get either blank spaces instead of information or other characters. Can't seem to find where the problem is. Note: do i need to put the fseek/fread out of the loop?

for (int i = 0; i < 6; i++) {
fseek(result, sizeof(results), SEEK_SET);
fread( & res.subject[i], sizeof(struct results) * i, 1, result);
printf("\nSubject:      %s \n", res.subject[i]);
fread( & res.mark[i], sizeof(struct results), 1, result);
printf("Mark:       %s \n", & res.mark[i]);
}
printf("\n\n"); //I wrote the data using a fwrite before and opened the file .bin in "wb"

Post a Reply

Replies

Oldest  Newest  Rating
0 c student · June 5, 2015
try checking the return values of your functions
0 sara v · June 4, 2015
 @cstudent There: http://paste.ofcode.org/8udDbWAZRRi5fyQc2F2Zhk
+1 c student · June 4, 2015
can we see your file declaration and the contents in your file?
  • 1

C

107,024 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator