Подсчитать количество слов в файле при помощи GETWORD - C (СИ)
Формулировка задачи:
Подсчитать количество слов в текст. файле.При помощи GETWORD.
Решение задачи: «Подсчитать количество слов в файле при помощи GETWORD»
textual
Листинг программы
#include <stdio.h>
#include <string.h>
int words_count(char * string, const char * delim) {
return ( strtok(string, delim) ) ? 1 + words_count(NULL, delim) : 0;
}
#define DELIM " \t\n"
#define STRING_SIZE 256
#define GET_STRING(str) ( scanf("%255[^\n]%*c", (str)) == 1 )
int main(void) {
char string[STRING_SIZE];
while ( printf("String: ") && GET_STRING(string) )
printf("%d words.\n", words_count(string, DELIM));
return 0;
}