Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     FILE *inputFile = fopen("students.txt", "r");
  7.     char endLineChar;
  8.     int i = 0, amountStudents = 1;
  9.     while (!feof(inputFile)){
  10.         endLineChar = fgetc(inputFile);
  11.         if (endLineChar == '\n')
  12.             amountStudents++;
  13.     }
  14.  
  15.     struct studentInfo {
  16.         long group;
  17.         char name[20];
  18.         int firstExam;
  19.         int secondExam;
  20.         int thirdExam;
  21.         int fourthExam;
  22.         int fifthExam;
  23.     };
  24.     struct studentInfo students[amountStudents];
  25.  
  26.     while (!feof(inputFile)) {
  27.         fscanf(inputFile, "%li %s %d %d %d %d %d", &students[i].group, students[i].name, &students[i].firstExam, &students[i].secondExam, &students[i].thirdExam, &students[i].fourthExam, &students[i].fifthExam);
  28.         i++;
  29.     }
  30.     fclose(inputFile);
  31.  
  32.     //printf("%s", students[0].name);
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement