Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- typedef struct {
- char Surname[16];
- char Name[16];
- char Patronymic[16];
- int recBookNumber;
- } student;
- void addStudent(FILE **target, student s)
- {
- fprintf(*target, "%s", s.Surname);
- fprintf(*target, "%s", s.Name);
- fprintf(*target, "%s", s.Patronymic);
- fprintf(*target, "%d", s.recBookNumber);
- fprintf(*target, "\n%s\n", "------------");
- }
- int main()
- {
- student* people=NULL;
- FILE *p;
- p=fopen("db.txt", "a+");
- if(p==NULL) { printf("failed"); return 0; }
- int i=1;
- while(1){
- people=realloc(people, sizeof(student)*i);
- fgets(people[i-1].Surname, 16, stdin);
- fgets(people[i-1].Name, 16, stdin);
- fgets(people[i-1].Patronymic, 16, stdin);
- char temp[16];
- fgets(temp, 16, stdin);
- people[i-1].recBookNumber=atoi(temp);
- printf("Continue?");
- char c;
- if((c=getchar())!='Y') break;
- else {getchar(); i++;}
- }
- for(int k=0; k<i; k++)
- {
- addStudent(&p, people[k]);
- }
- fclose(p);
- p=NULL;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement