Mail Archives: djgpp/1999/06/10/09:33:46
Hi all
I'd like some info on what I am doing wrong here. This block of code
works perfectly in Borland C 3.1 and in MS QC ver 6 but gives an
erroneous result in DJGPP. It reads a binary file into an array of
structures and displays to screen. Here is the code.
Thanks Pete
int read_file(void);
typedef struct
{
char title[30];
char author[30];
int year;
} BOOK;
main()
{
clrscr();
if(read_file());
// else
// {
// get_data();
// write_file();
// }
}
int read_file(void)
{
int i = 0;
FILE *infile;
BOOK book[5];
if ((infile = fopen("A:\\book.bin", "rb")) == NULL)
{
printf("\n\nCould not open file");
printf("\n\nPlease check disk with file 'book.bin' is in the A:
drive");
printf("\n\nExiting the program");
return 0;
}
else
{
for (i = 0; i < 5; i++)
{
fread(&book[i], sizeof(book[i]), 1, infile);
printf("%s %s %d\n", book[i].title, book[i].author,
book[i].year);
}
}
}
- Raw text -