Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- int Counter(char* p);
- int main()
- {
- int n, c;
- char* text;
- cout << "Please, enter text length: ";
- cin >> n;
- text = new char[n+1];
- cout << "Please, enter text: ";
- cin.get();
- cin.getline(text, n);
- //cout << endl << text;
- c = Counter(text);
- cout << endl << endl << c << " words" << endl;
- return 0;
- }
- int Counter(char* p)
- {
- int counter = 0;
- char*razd2 = ",;:!?. ";
- char *p2 = strtok(p,razd2);
- while(p2 != NULL)
- {
- counter ++;
- //cout << p2 << endl;
- p2 = strtok(NULL,razd2); //Если первый параметр NULL, то работает со строкой из первого вызова(в данном случае р)
- }
- return counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement