Тема: Файли
Доброго вечора!
Написала програму, яка реалізує наступне завдання:
"Вхідні дані (поля структури) вводяться з клавіатури і після введення записуються у файл (окрема функція); програма має можливість дописувати дані у файл (окрема функція); дані з файлу виводяться на екран (окрема функція)"
Проблема в тому, що файл то створюється, але в нього нічого не записується (навіть перше повідомлення). Не можу знайти тут помилку. Буду вдячна за допомогу)
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>    
#define MAX 50
using namespace std;
struct SCHL
{
    char NAME[30];
    char GROUP[10];
    int SUBJ[5];
};
void input(SCHL LEARN[], int N, FILE* students)
{
    for (int i = 0; i < N; i++)
    {
        printf("Enter the student's surname: ");
        scanf_s("%s", &LEARN[i].NAME);
        printf("Enter the name of the group in which the student is studying: ");
        scanf_s("%s", &LEARN[i].GROUP);
        fprintf(students, "%s %s ", LEARN[i].NAME, LEARN[i].GROUP);
        printf("Enter 5 grades from the subjects (Mathematics, Informatics, Programming, Graphics, Foreign): ");
        for (int j = 0; j < 5; j++)
        {
            scanf_s("%i", &LEARN[i].SUBJ[j]);
            fprintf(students, "%i ", LEARN[i].SUBJ[j]);
        }
        printf("\n");
    }
}
void condition(SCHL LEARN[], int N, FILE* students)
{
    int k = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (LEARN[i].SUBJ[j] == 2)
            {
                printf("%s\t\t%s\n", LEARN[i].NAME, LEARN[i].GROUP);
                fprintf(students, "\n%s %s\n", LEARN[i].NAME, LEARN[i].GROUP);
                k++;
                break;
            }
        }
    }
    if (k == 0)
    {
        printf("The entered students have no negative marks!\n");
        fprintf(students, "\nThe entered students have no negative marks!\n");
    }
}
void pluss(SCHL LEARN[], int x, FILE* students)
{
    switch (x)
    {
    case 1:
        int n;
        printf("Please enter the number of students whose data will be entered later : ");
        scanf_s("%i", &n);
        for (int i = 0; i < n; i++)
        {
                        printf("Enter the student's surname: ");
                scanf_s("%s", &LEARN[i].NAME);
                printf("Enter the name of the group in which the student is studying: ");
                scanf_s("%s", &LEARN[i].GROUP);
                fprintf(students, "%s %s ", LEARN[i].NAME, LEARN[i].GROUP);
                printf("Enter 5 grades from the subjects (Mathematics, Informatics, Programming, Graphics, Foreign): ");
                for (int j = 0; j < 5; j++)
                {
                   scanf_s("%i", &LEARN[i].SUBJ[j]);
                   fprintf(students, "%i ", LEARN[i].SUBJ[j]);
                 }
                printf("\n");
            }
        break;
    default:
        printf("Completion..\n");
        fprintf(students, "Completion...\n");
        break;
    }
}
void output(SCHL LEARN[], FILE* students)
{
    for (int i= 0; i < !feof(students); i++)
    {
        for (int j = 0; j < 5; j++)
        {
            fscanf(students, "%s %s %i", &LEARN[i].NAME, &LEARN[i].GROUP, &LEARN[i].SUBJ[j]);
            printf("%s %s %i", LEARN[i].NAME, LEARN[i].GROUP, LEARN[i].SUBJ[j]);
        }
        printf("\n");
    }
}
int main()
{
    int N, x;
    SCHL LEARN[MAX];
    FILE* students;
    students = fopen("students_info.txt", "w+");
    fprintf(students, "You start filling in the table!\n");
    printf("You start filling in the table!\nPlease enter the number of students whose data will be entered later: ");
    scanf_s("%i", &N);
    input(LEARN, N, students);
    printf("Students with negative grades:\n");
    condition(LEARN, N, students);
    printf("Program menu:\n1) Add several new entries;\n0) Finish the job.\n");
    do
    {
        printf("\nEnter the menu item: ");
        scanf_s("%d", &x);
        pluss(LEARN, x, students);
    } while (x != 0);
    printf("Output data from the file to the screen:\n");
    output(LEARN, students);
    fclose(students);
    system("pause");
    return 0;
}