I want to read this data from a file and perform the same task that it is performing right now. I just want to know how i can do it from a file. Here is the code:
Code:
#include <stdio.h>
#include <string.h>
#define NUM_STU 5
typedef struct
{
char name[26];
int midterm[3];
int final;
} STUDENT;
int main (void)
{
STUDENT *pStuPtr;
STUDENT stuAry[NUM_STU] =
{
{"Charles, George",{85, 94, 79}, 93},
{"Adams, Karin", {75, 91, 89}, 89},
{"Nguyen, Tuan", {87, 88, 89}, 90},
{"Oh, Bill", {78, 96, 88}, 91},
{"Chavez, Maria", {83, 79, 93}, 91},
};
printf("Unsorted data:\n");
for (pStuPtr = stuAry;
pStuPtr < stuAry + NUM_STU;
pStuPtr++)
printf("%-26s %4d %4d %4d %4d\n",
pStuPtr->name,
pStuPtr->midterm[0],
pStuPtr->midterm[1],
pStuPtr->midterm[2],
pStuPtr->final);
printf("\n");
return 0;
}
thanx for any advice.