Guest User

Untitled

a guest
Mar 19th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <stdio.h>
  2. typedef struct list
  3. {
  4. char sur[128];
  5. int ball;
  6. int mark;
  7. }list;
  8. int swap(const void *a,const void *b);
  9. int addstud(char *std);
  10. int sortstud(char *std);
  11.  
  12. int main()
  13. {
  14. list stud;
  15. int i=0,menu,t=0;
  16. float n=0;
  17. char std[] = "stud.txt";
  18. FILE *fl;
  19.  
  20. while (1)
  21. {
  22. printf("1)Add new studentn2)Show list of studentsn3)Change info about studentn4)Delete studentn5)Exitn");
  23. scanf("%d",&menu);
  24. switch (menu)
  25. {
  26. case 1:
  27. addstud(std);
  28. break;
  29. case 2:
  30. viewinfo(std);
  31. break;
  32. case 3:
  33. sortstud(std);
  34. break;
  35. case 4:
  36. delstud(std,n,t);
  37. t++;
  38. break;
  39.  
  40. case 5:
  41.  
  42. return 0;
  43. default:
  44. printf("Eror, please try again!n");
  45. //system("cls");
  46. }
  47.  
  48. }
  49. }
  50.  
  51. int addstud(char *std)
  52. {
  53. FILE *fl;
  54. fl = fopen(std, "a");
  55. list stud;
  56. if (fl == 0)
  57. {
  58. fprintf(stderr, "Error open filen");
  59. return 1;
  60. }
  61. printf("Enter surname student: ");
  62. scanf("%s",stud.sur);
  63. //printf("%s",stud.sur);
  64. //fprintf(fl,"%-9s",stud->sur);
  65. printf("Enter scores of student: ");
  66. scanf("%d",&stud.ball);
  67. //printf("%d",stud.ball);
  68. //fprintf(fl,"%-4d",stud->ball);
  69. stud.mark = 0;
  70. fwrite(&stud,sizeof(list),1,fl);
  71. printf("n");
  72. //fprintf(fl,"%-4dn",stud->mark);
  73. fclose(fl);
  74. printf("Press Enter for continue...n");
  75. //getch();
  76. //system("cls");
  77. return(0);
  78. }
  79.  
  80. int sortstud(char *std)
  81. {
  82. FILE *fl;
  83. int j = 0,i = 0, n = 0;
  84. list stud[10];
  85. int temp;
  86. list studt;
  87. fl = fopen(std,"r+b");
  88. fseek(fl,0,SEEK_END);
  89. long size = ftell(fl);
  90. fseek(fl,0,SEEK_SET);
  91. int sizefile = sizeof(list);
  92. n = (size/sizefile);
  93. qsort(stud,n,sizeof(list),swap);
  94. fclose(fl);
  95. }
  96. int swap(const void *a,const void *b)
  97. {
  98. return ((list*)a)->ball ((list*)b)->ball;
  99. }
Add Comment
Please, Sign In to add comment