#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <windows.h>
signed main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
char s[80] = {0};
int count = 0, word = 0, i = 0;
printf("Введите строку: ");
scanf("%99[^\n]", s);
while (s[i] == ' ' && s[i] != '\0') {
i++;
}
while (s[i] != '\0') {
if (s[i] != ' ' && word == 0)
{
word = 1;
count++;
else if (s[i] == ' ')
word = 0;
printf("Количество слов в строке: %i", count);
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <windows.h>
signed main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
char s[80] = {0};
int count = 0, word = 0, i = 0;
printf("Введите строку: ");
scanf("%99[^\n]", s);
while (s[i] == ' ' && s[i] != '\0') {
i++;
}
while (s[i] != '\0') {
if (s[i] != ' ' && word == 0)
{
word = 1;
count++;
}
else if (s[i] == ' ')
word = 0;
i++;
}
printf("Количество слов в строке: %i", count);
return 0;
}