tlan16

Untitled

Apr 17th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <conio.h>
  5.  
  6. const int NAMELEN=30;
  7. const int MAXCLASSSIZE=10;
  8.  
  9. typedef struct StudentRec {
  10.     char lastname[NAMELEN];
  11.     char firstname[NAMELEN];
  12.     long int ID;
  13.     int finalmark;
  14. }Student;
  15.  
  16. typedef struct ClassRec {
  17.     int size;
  18.     Student classlist[MAXCLASSSIZE];
  19. }Class;
  20.  
  21. void ReadStudents (Class *classpar, FILE *stuFile);
  22. void PrintStuRec (Student *studpar);
  23. void PrintStudents (Class *classpar);
  24.  
  25. void main() {
  26.     FILE *inputPtr;
  27.     Class clist;
  28.     inputPtr=fopen("student.dat","r");
  29.     if(inputPtr==NULL)
  30.         printf("Error openning input file. \n");
  31.     else {
  32.         ReadStudents(&clist,inputPtr);
  33.         PrintStudents(&clist);
  34.         }
  35.  
  36.     getch();
  37. } /*end main */
  38.  
  39.     void ReadStudents (Class *classpar, FILE *studFile)
  40.     {
  41.         int i;
  42.         long int idnumber;
  43.         char fname[NAMELEN];
  44.         char lname[NAMELEN];
  45.         int mark;
  46.         i=0;
  47.  
  48.         while(studFile != NULL) {
  49.             scanf("%li %s %s %i", &idnumber, fname, lname, &mark);
  50.             classpar->classlist[i].ID = idnumber;
  51.             strcpy(classpar->classlist[i].firstname,fname);
  52.             strcpy(classpar->classlist[i].lastname,lname);
  53.             classpar->classlist[i].finalmark = mark;
  54.             i++;
  55.         }
  56.  
  57.     } /* end function read */
  58.  
  59.     void PrintStuRec (Student *stupar)
  60.     {
  61.         printf("%-10li %-8s %-8s %2i\n", stupar->ID, stupar->firstname, stupar->lastname, stupar->finalmark);
  62.     } /* end function */
  63.  
  64.     void PrintStudents (Class *classpar)
  65.     {
  66.         int i;
  67.         i=0;
  68.         while(classpar != NULL); {
  69.             PrintStuRec(classpar->classlist[i]);
  70.             i++;
  71.         }
  72.     }
Advertisement
Add Comment
Please, Sign In to add comment