Advertisement
Guest User

my work

a guest
Dec 6th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. typedef struct {
  7. char Surname[16];
  8. char Name[16];
  9. char Patronymic[16];
  10. int recBookNumber;
  11. } student;
  12.  
  13. void addStudent(FILE **target, student s)
  14. {
  15. fprintf(*target, "%s", s.Surname);
  16. fprintf(*target, "%s", s.Name);
  17. fprintf(*target, "%s", s.Patronymic);
  18. fprintf(*target, "%d", s.recBookNumber);
  19. fprintf(*target, "\n%s\n", "------------");
  20. }
  21.  
  22. int main()
  23. {
  24. student* people=NULL;
  25. FILE *p;
  26. p=fopen("db.txt", "a+");
  27. if(p==NULL) { printf("failed"); return 0; }
  28. int i=1;
  29. while(1){
  30. people=realloc(people, sizeof(student)*i);
  31. fgets(people[i-1].Surname, 16, stdin);
  32. fgets(people[i-1].Name, 16, stdin);
  33. fgets(people[i-1].Patronymic, 16, stdin);
  34. char temp[16];
  35. fgets(temp, 16, stdin);
  36. people[i-1].recBookNumber=atoi(temp);
  37. printf("Continue?");
  38. char c;
  39. if((c=getchar())!='Y') break;
  40.  
  41. else {getchar(); i++;}
  42. }
  43. for(int k=0; k<i; k++)
  44. {
  45. addStudent(&p, people[k]);
  46. }
  47.  
  48. fclose(p);
  49. p=NULL;
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement