Advertisement
Guest User

lab5

a guest
May 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. const int N= 100;
  7.  
  8. int Words(char str[N]){
  9.     int number_words=0;
  10.     char *pstr;
  11.     pstr=strtok(str," ");
  12.     while (pstr!=NULL)
  13.     {
  14.         pstr=strtok(NULL," ");
  15.         number_words++;
  16.     }
  17.     return (number_words);
  18. }
  19.  
  20. int main(int argc, char** argv) {
  21.     setlocale(LC_ALL, "RUSSIAN");
  22.     char str[N];
  23.     cout << "Введите текст: ";
  24.     cin.getline ( str, N);
  25.     cout << "В тексте "<< Words(str)<<" слов(а)." <<endl;
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement