Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <conio.h>
- const int NAMELEN=30;
- const int MAXCLASSSIZE=10;
- typedef struct StudentRec {
- char lastname[NAMELEN];
- char firstname[NAMELEN];
- long int ID;
- int finalmark;
- }Student;
- typedef struct ClassRec {
- int size;
- Student classlist[MAXCLASSSIZE];
- }Class;
- void ReadStudents (Class *classpar, FILE *stuFile);
- void PrintStuRec (Student *studpar);
- void PrintStudents (Class *classpar);
- void main() {
- FILE *inputPtr;
- Class clist;
- inputPtr=fopen("student.dat","r");
- if(inputPtr==NULL)
- printf("Error openning input file. \n");
- else {
- ReadStudents(&clist,inputPtr);
- PrintStudents(&clist);
- }
- getch();
- } /*end main */
- void ReadStudents (Class *classpar, FILE *studFile)
- {
- int i;
- long int idnumber;
- char fname[NAMELEN];
- char lname[NAMELEN];
- int mark;
- i=0;
- while(studFile != NULL) {
- scanf("%li %s %s %i", &idnumber, fname, lname, &mark);
- classpar->classlist[i].ID = idnumber;
- strcpy(classpar->classlist[i].firstname,fname);
- strcpy(classpar->classlist[i].lastname,lname);
- classpar->classlist[i].finalmark = mark;
- i++;
- }
- } /* end function read */
- void PrintStuRec (Student *stupar)
- {
- printf("%-10li %-8s %-8s %2i\n", stupar->ID, stupar->firstname, stupar->lastname, stupar->finalmark);
- } /* end function */
- void PrintStudents (Class *classpar)
- {
- int i;
- i=0;
- while(classpar != NULL); {
- PrintStuRec(classpar->classlist[i]);
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment