/* This program reads student data from a file, into array 
   of structures, then facilitates queries */
/* By Douglas Desario on 11/28/06 */

#include<stdio.h>
#define MAX 6 /* one more than number of students, to start index from 1 */

struct data{
  char name[50];
  char grade;
  int score;
}stud_id[MAX], *dPtr;

void main()
{
  int i;
  FILE *fp;

  fp = fopen("student.txt", "r");
  
  for(i=1; i<MAX; i++){
    fscanf(fp, "%s ", &stud_id[i].name);
    fscanf(fp, "%d ", &stud_id[i].score);
    fscanf(fp, "%c ", &stud_id[i].grade);
  }

printf("Enter which student data you need (1 to 5):");
scanf("%d",&i);
dPtr=&stud_id[i];

printf("The values are: %s %d %c\n\n",(*dPtr).name,dPtr->score,dPtr->grade);

  fclose(fp);
}

