Hello, everyone. I'm a student and I was assigned a coursework and I haven't had any issues with my last coursework/programming over all but this one gets me. I have to make a program for a group of students with a name, faculty number and marks in 3 subjects. The program should:
1. Create an empty file (done)
2. Add data for the students to the file (done)
3. Change the files by an inserted faculty number (done)
4. Seperately calculate the arithmetic average of the 3 subjects and output them in a text file
Qt Code:
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct Student {
  6.  
  7. char Name[50];
  8. char FN[7];
  9. int marks[3];
  10. float SRU;
  11. };
  12. char fileName[31];
  13. FILE *fs;
  14. Student st;
  15.  
  16. void createFile(){ //1
  17.  
  18. fs=fopen(fileName,"wb");
  19. fclose(fs);
  20. }
  21.  
  22. void ReadStudent (Student *st) {
  23.  
  24. int i;
  25. printf ("Name: "); scanf("%s",st->Name); getchar();
  26. printf ("Faculty number: "); scanf("%s",st->FN);
  27. printf ("Insert the marks of Physics(1), Mathematics(2) and Programming (3): \n");
  28. for (i=0;i<3;i++) {
  29. printf ("Subject %d-a: ",i+1);
  30. scanf ("%d",&st->marks[i]);
  31. }
  32. }
  33. void addStudents(){ //2
  34. fs=fopen(fileName, "a+b");
  35. char c;
  36. do {
  37. ReadStudent(&st);
  38. fwrite(&st, sizeof(Student),1,fs);
  39. printf("More (y/n)?"); c=getchar(); getchar();
  40.  
  41. }while(c=='y');c=getchar(); getchar();
  42. fclose(fs);
  43. }
  44. void changeData(){ // 3
  45.  
  46. char j[11];
  47. int k=0;
  48. // if(!exist(fileName)){
  49. // printf("The file's not created\n\n"); return;
  50.  
  51. printf("Insert the faculty number of the student whose data you'd like you change "); gets(j);
  52. fs=fopen (fileName, "r+b");
  53. fread(&st,sizeof(Student),1,fs);
  54. while (!feof(fs)) {
  55. if(strcmp(st.FN,j)==0) {
  56. ReadStudent(&st);
  57. fseek(fs,-(long)sizeof(Student), SEEK_CUR);
  58. fwrite(&st, sizeof(Student),1,fs);
  59. printf("The data has been changed\n");
  60. k++;
  61. break;
  62. }
  63. fread(&st, sizeof(Student),1,fs);
  64. }if (k==0) printf("No data for the student with that FN\n");
  65. fclose(fs);
  66. }
  67.  
  68. void arithmAv()
  69. {
  70. fs=fopen(fileName,"rb");
  71. FILE *txt=fopen("Students.txt","wt");
  72. int count=0;
  73. //Here I should write something but idk what...
  74. fprintf(txt, "There are %d student(s)\n",count);
  75. fclose(fs);
  76. fclose(txt);
  77. }
  78.  
  79. void main() {
  80. system("chcp 1251");
  81. printf("File name: ");
  82. gets(fileName);
  83. int answer;
  84. do{
  85. printf("\n\nMenu:\n");
  86. printf("1-Create an empty file\n");
  87. printf("2-Add data for a student to the file\n");
  88. printf("3-Change data for a student by FN\n");
  89. printf("4-Arithmetic average of the 3 subjects seperately and output in text file.\n");
  90. printf("0-Exit\n");
  91. char c;
  92. printf("Choose: "); scanf("%d", &answer);c=getchar(); getchar();
  93. switch (answer){
  94. case 1:createFile(); break;
  95. case 2:addStudents(); break;
  96. case 3:changeData(); break;
  97. case 4:arithmAv(); break;
  98. }
  99. }while(answer !=0);
  100. }
To copy to clipboard, switch view to plain text mode 

Please, help me! I'm totaly bumped I have no idea how to proceed...