Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main ()
- {
- int counter2 = 0;
- int counter =0;
- int prevCounter2 = 0;
- char str[256];
- cin.getline(str, 256);
- char c;
- cout<<"Enter symbol: ";
- cin>>c;
- char * pch = strtok (str," ");
- while (pch != NULL)
- {
- prevCounter2 = counter2;
- for (int i=0;i<strlen(pch);i++)
- {
- if (pch[i] == c)
- counter++;
- }
- if (counter == 2){
- prevCounter2 = counter2;
- counter2++;
- for (int i=0;i<strlen(pch);i++)
- {
- if (!isalpha(pch[i]))
- {
- counter2= prevCounter2;
- }
- }
- counter = 0;
- pch = strtok (NULL, " ");
- }
- }
- cout<<"Symbol "<<c<<" 2 times in words: "<<counter2<<endl;
- }
Add Comment
Please, Sign In to add comment