I cannot understand why there is no record of the result in the G.bin file the task condition is to write part of the line before or after 0 in the second file you need to write down the part where the amount is greater.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main()
{
    FILE* fa;
    errno_t err = fopen_s(&fa, "F.bin", "wb");
    if (err != 0)
    {
        printf("Error opening file F.bin\n");
        return 1;
    }
    printf("Enter numbers:\n");
    int sum_before = 0;
    int sum_after = 0;
    int num;
    int zero_encountered = 0;
    char input[256];
    fgets(input, sizeof(input), stdin);
    size_t input_length = strlen(input);
    if (input[input_length - 1] == '\n')
    {
        input[input_length - 1] = '\0'; // Видалити символ нового рядка
    }
    fwrite(input, sizeof(char), strlen(input), fa);
    fclose(fa);
    char* token;
    char* nextToken = NULL;
    token = strtok_s(input, " ", &nextToken);
    while (token != NULL)
    {
        num = atoi(token);
        if (num == 0)
        {
            zero_encountered = 1;
        }
        if (!zero_encountered)
        {
            sum_before += num;
        }
        else
        {
            sum_after += num;
        }
        token = strtok_s(NULL, " ", &nextToken);
    }
    FILE* fb;
    err = fopen_s(&fb, "G.bin", "wb");
    if (err != 0)
    {
        printf("Error opening file G.bin\n");
        return 1;
    }
    if (sum_before > sum_after)
    {
        size_t part_length = strlen(input) - strlen(nextToken) - 1; // Обчислюємо довжину першої частини
        fwrite(input, sizeof(char), part_length, fb);
    }
    else
    {
        fwrite(nextToken, sizeof(char), strlen(nextToken), fb);
    }
    fclose(fb);
    printf("Результат успішно записано у файл G.bin\n");
    return 0;
}
data from the keyboard:
12 45 78 0 312 545 899 
data that should be in the G.bin file:
312 545 899 
 
     
    