С файла считать третью строку и посчитать количество слов в этой строке — C++(Си)

#include <stdio.h>
#include <string.h>
 
int main()
{
        FILE *fin;
        char str[300];
        char *word = NULL;
        int count = 0;
 
        fin = fopen("input.txt", "r");
        fgets(fin, str, 300);
        fgets(fin, str, 300);
        fgets(fin, str, 300);
 
        word = strtok (str, " ,.");
        while (word)
        {
                count++;
                word = strtok (NULL, " ,.");
        }
        printf("%i\n", count);
        return 0;
}

Leave a Comment