Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct list
- {
- char sur[128];
- int ball;
- int mark;
- }list;
- int swap(const void *a,const void *b);
- int addstud(char *std);
- int sortstud(char *std);
- int main()
- {
- list stud;
- int i=0,menu,t=0;
- float n=0;
- char std[] = "stud.txt";
- FILE *fl;
- while (1)
- {
- printf("1)Add new studentn2)Show list of studentsn3)Change info about studentn4)Delete studentn5)Exitn");
- scanf("%d",&menu);
- switch (menu)
- {
- case 1:
- addstud(std);
- break;
- case 2:
- viewinfo(std);
- break;
- case 3:
- sortstud(std);
- break;
- case 4:
- delstud(std,n,t);
- t++;
- break;
- case 5:
- return 0;
- default:
- printf("Eror, please try again!n");
- //system("cls");
- }
- }
- }
- int addstud(char *std)
- {
- FILE *fl;
- fl = fopen(std, "a");
- list stud;
- if (fl == 0)
- {
- fprintf(stderr, "Error open filen");
- return 1;
- }
- printf("Enter surname student: ");
- scanf("%s",stud.sur);
- //printf("%s",stud.sur);
- //fprintf(fl,"%-9s",stud->sur);
- printf("Enter scores of student: ");
- scanf("%d",&stud.ball);
- //printf("%d",stud.ball);
- //fprintf(fl,"%-4d",stud->ball);
- stud.mark = 0;
- fwrite(&stud,sizeof(list),1,fl);
- printf("n");
- //fprintf(fl,"%-4dn",stud->mark);
- fclose(fl);
- printf("Press Enter for continue...n");
- //getch();
- //system("cls");
- return(0);
- }
- int sortstud(char *std)
- {
- FILE *fl;
- int j = 0,i = 0, n = 0;
- list stud[10];
- int temp;
- list studt;
- fl = fopen(std,"r+b");
- fseek(fl,0,SEEK_END);
- long size = ftell(fl);
- fseek(fl,0,SEEK_SET);
- int sizefile = sizeof(list);
- n = (size/sizefile);
- qsort(stud,n,sizeof(list),swap);
- fclose(fl);
- }
- int swap(const void *a,const void *b)
- {
- return ((list*)a)->ball ((list*)b)->ball;
- }
Add Comment
Please, Sign In to add comment