fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. char s[80];
  6. int slovo, count = 0;
  7. system("chcp 1251");
  8. system("cls");
  9. cout << "Введите строку: " << endl;
  10. cin.get(s, 80);
  11. int i = 0;
  12. while (s[i] == ' ' && s[i] != '\0')
  13. i++;
  14. slovo = 0;
  15. while (s[i] != '\0') {
  16. if (s[i] != ' ' && slovo == 0)
  17. {
  18. slovo = 1;
  19. count++;
  20. }
  21. else if (s[i] == ' ')
  22. slovo = 0;
  23. i++;
  24. }
  25. cout << "Количество слов в строке " << count;
  26. cin.get(); cin.get();
  27. return 0;
  28. }
Success #stdin #stdout #stderr 0s 4260KB
stdin
hello world
stdout
Введите строку: 
Количество слов в строке 2
stderr
sh: 1: chcp: not found
sh: 1: cls: not found