0

user input not saving to file

hi guys, so i created 2 text file where my user and staff data respectively can be stored but my data doesn't get stored but the code is running perfectly. This is my code FILE *usr; FILE *staf; usr = fopen("users.txt","a+"); staf = fopen("staff.txt","a+"); // some data to be collected if (choice == 's') { fscanf(staf,"staffs: %d/%d/%d %s %s %s %s %s %d %s\n ",&add.month,&add.day,&add.year,add.name,choice,add.staff.username,add.password,add.email,&add.number); fprintf(staf,"staffs: %d/%d/%d %s %s %s %s %s %d %s\n ",&add.month,&add.day,&add.year,add.name,choice,add.staff.username,add.password,add.email,&add.number); fclose(staf); } else if (choice == 'u') { fscanf(usr," %d/%d/%d %s %s %s %s %s %d %s\n ",&add.month,&add.day,&add.year,add.name,choice,add.user.username,add.password,add.email,&add.number); fprintf(usr," %d/%d/%d %s %s %s %s %s %d %s\n",&add.month,&add.day,&add.year,add.name,choice,add.user.username,add.password,add.email,&add.number); fclose(usr); } else { goto personnel; }

6th Apr 2020, 11:05 PM
Miriam
Miriam - avatar
2 Respostas
+ 1
Tries to change the opening mode of the file. Instead of 'a+' puts 'a' if you only want to write in the file, or 'r' if you only want to read, or 'w+' if you want to read and write.
7th Apr 2020, 1:45 AM
1001pepi
1001pepi - avatar
+ 1
The opening mode 'a+'instead of setting the cursor at the beginning of the file sets it at the end.
7th Apr 2020, 1:46 AM
1001pepi
1001pepi - avatar