Дан файл, содержащий некоторый текст. Отредактировать файл: после каждой фразы в скобках указать число слов в ней

Только начал изучать потоки в Си. Не совсем понимаю почему при исходном файле...

This is an ordinary text with brackets that does not carry any meaning and is intended to exist independently, regardless of the meaning of the text and the reasons for its existence. It can contain any information (absolutely any) up to the one that will be a "white noise" of various encoding characters Windows-1251 (character set and encoding, which is the standard 8-bit encoding for Russian versions of Microsoft Windows up to the 10th version).

Выводит три текста за раз...

This is an ordinary text with brackets that does not carry any meaning and is intended to exist independently, regardless of the meaning of the text and the reasons for its existence. It can contain any information (absolutely any) up to the one that will be a "white noise" of various encoding characters Windows-1251 (character set and encoding, which is the standard 8-bit encoding for Russian versions of Microsoft Windows up to the 10th version).

This is an ordinary text with brackets that does not carry any meaning and is intended to exist independently, regardless of the meaning of the text and the reasons for its existence. It can contain any information (absolutely any) 28 to the one that will be a "white noise" of various encoding characters Windows-1251 (character set and encoding, which is the standard 8-bit encoding for Russian versions of Microsoft Windows up to the 10th version) 14ion) 1

This is an ordinary text with brackets that does not carry any meaning and is intended to exist independently, regardless of the meaning of the text and the reasons for its existence. It can contain any information (absolutely any) 27 to the one that will be a "white noise" of various encoding characters Windows-1251 (character set and encoding, which is the standard 8-bit encoding for Russian versions of Microsoft Windows up to the 10th version) 17ion) 1

Вместо...

This is an ordinary text with brackets that does not carry any meaning and is intended to exist independently, regardless of the meaning of the text and the reasons for its existence. It can contain any information (absolutely any) 2 up to the one that will be a "white noise" of various encoding characters Windows-1251 (character set and encoding, which is the standard 8-bit encoding for Russian versions of Microsoft Windows up to the 10th version) 21.

#include <stdlib.h>
#include <string.h>
#define ARRAY_SIZE 10000

int main() {
    FILE *file = fopen("Ex1_test_file.txt", "r+");
    char text[ARRAY_SIZE];
    int i = 0;
    int words = 0;
    if (file != NULL)
    {
        printf("\nFile opened successfully\n\n");

        while (!feof(file))
        {
            fscanf(file, "%c", &text[i]);
            if(text[i] == '(')
            {
                words = 0;
                while(fscanf(file, "%c", &text[i]) != ')')
                {
                    if (text[i] == ' ' && text[i+1] != ' ')
                        words++;
                    if (text[i] == ')')
                    {
                        words++;
                        fprintf(file, " %d", words);
                        words = 0;
                    }
                    i++;
                }

            }
        }
    }

    fclose(file);
    printf("\n\nFile closed succesfully\n\n");
    return 0;
}``` 

Ответы (0 шт):