Zyava
Member | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору #include <stdio.h> int main() { char str[256]; printf("Enter string\n"); gets(str); printf("%s", str); int words_count = 0; int is_prev_char_not_space = 1; if (str[0] == ' ' || str[0] == '\t' || str[0] == '\n') is_prev_char_not_space = 0; int i = 1; while(str[i]) { if (str[i] == ' ' || str[i] == '\t' || str[i] == '\n') { if (is_prev_char_not_space == 1) words_count++; is_prev_char_not_space = 0; } else is_prev_char_not_space = 1; i++; } if (str[i] != ' ' && str[i] != '\t') words_count++; printf("\nWords count: %d", words_count); return 0; } |