1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string new_sentence;
char sentence[100],*p;
cout<<"Write a sentence.\n";
cin.getline(sentence,99);
p=strtok(sentence," ");
while(p!=NULL){
if(p=="a"){
new_sentence+="a";
}
p=strtok(NULL," ");
}
cout<<new_sentence<<endl;
cout<<"Press ENTER to end the program. ";
cin.get();
return 0;
}
|
In this program even when
p is "a",
new_sentence does not change.
Thanks.
Last edited on
To compare two c strings you use std::strcmp.
If you prefer you can convert one of the c strings to std::string and use ==.
Last edited on
How did I forget! Thanks again Peter87.