#include <stdio.h>
#include <stdlib.h>
#define fileName "book.txt"
#define ROWS
2
typedef struct
{
char name[10];
int id;
int score;
char grade[10];
}student;
int main()
{
student jim[ROWS];
int row;
FILE * infile;
if ((infile = fopen(fileName, "r")) == NULL)
{
fprintf(stderr, "Could not open data file.\n");
exit(EXIT_FAILURE);
}
for (row = 0; row < ROWS; row++)
fscanf(infile, "%s %d %d %s",
jim[row].name, &jim[row].id, &jim[row].score, jim[row].grade);
if (ferror(infile))
{
fprintf(stderr, "Error getting data from file.\n");
exit(EXIT_FAILURE);
}
for (row = 0; row < ROWS; row++)
{
printf("%s
%d
%d
%s\n", jim[row].name, jim[row].id, jim[row].score, jim[row].grade);
}
return 0;
}