Advertisement
ilyakanyshev

task2__dop

Jan 24th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int Counter(char* p);
  7.  
  8. int main()
  9. {
  10.     int n, c;
  11.     char* text;
  12.     cout << "Please, enter text length: ";
  13.     cin >> n;
  14.     text = new char[n+1];
  15.     cout << "Please, enter text: ";
  16.     cin.get();
  17.     cin.getline(text, n);
  18.     //cout << endl << text;
  19.     c = Counter(text);
  20.     cout << endl << endl << c << " words" << endl;
  21.     return 0;
  22. }
  23.  
  24. int Counter(char* p)
  25. {
  26.     int counter = 0;
  27.     char*razd2 = ",;:!?. ";
  28.     char *p2 = strtok(p,razd2);
  29.     while(p2 != NULL)
  30.     {
  31.         counter ++;
  32.         //cout << p2 << endl;
  33.         p2 = strtok(NULL,razd2); //Если первый параметр NULL, то работает со строкой из первого вызова(в данном случае р)
  34.     }
  35.     return counter;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement