#include #include // examples of fscanf(). Read in each from file and save // in variables (email, major, year) then output to // the screen #define MAXLINE 80 int main(void) { FILE *file; char email[MAXLINE]; char major[MAXLINE]; int year; if (!(file = fopen("students.txt", "r"))) { printf("\aCan't open file.\n"); exit (1); } printf("CS50 W14 Hackers List\n"); // A terminating null character is automatically added at the end // of the stored email and major by fscanf() while (fscanf(file, "%s %s %d", email, major, &year) == 3) printf("%s %s %3d\n", email, major, year); fclose(file); return 0; }