Имеется часть кода:
struct St
{
char Name[30];
int math;
int phys;
int inf;
int chem;
int dateOfBirth;
int group;
double ball;
} Students;
void addStudent() {
f1 = fopen("list.txt", "w");
cout << "Enter the Name of student: ";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
gets_s(Students.Name, 29);
cout << "Enter the math ball: ";
cin >> Students.math;
cout << "Enter the informatics ball: ";
cin >> Students.inf;
cout << "Enter the physics ball: ";
cin >> Students.phys;
cout << "Enter the chemistry ball: ";
cin >> Students.chem;
cout << "Enter the date of birth: ";
cin >> Students.dateOfBirth;
cout << "Enter the group of student: ";
cin >> Students.group;
cout << "Enter the average ball: ";
cin >> Students.ball;
fwrite(&Students, 1, sizeof(Students), f1);
fclose(f1);
}
Задача - считать данные с консоли, записать их в переменные структуры и позже записать данные структуры в файл. Сделал таким образом, однако в файле получаю:
Sergei юююююююююююююююююююююю
Р >ж
$@
Думаю, что ошибка в fwrite()
, но не до конца понимаю, как в нее правильно записать параметры, ибо в структуре переменные разных типов