/* Reads the grades of 10 students in 3 exams form an input file and prints the grades and average in a tabular form Author: Bashir Ghandi Date: 18-09-1999 */ #include main() { long int id; int i; float ex1, ex2, ex3, avg; FILE *inp; char in_file[25]; do { printf ("Enter the name of input file >") ; scanf("%s", in_file); inp=fopen(in_file, "r"); if (inp == NULL) printf ("Cannot open %s for input\n", in_file) ; } while (inp==NULL); printf("\nID\tEXAM1\tEXAM2\tEXAM3\tAVERAGE\n"); for (i=1; i<=10; i++) { fscanf(inp, "%ld%f%f%f",&id, &ex1, &ex2, &ex3); avg=(ex1+ex2+ex3)/3; printf("%ld\t%.2f\t%.2f\t%.2f\t%.2f\n", id,ex1,ex2,ex2,avg); } fclose(inp); return 0; }