#include
#include
using namespace std;
int main() {
// string s;
// getline(cin,s);
char str[1000];
cin>>str;
char *ptr;
ptr=strtok(str,"isupper(str)");
while(ptr!=NULL){
cout<<ptr<<endl;
ptr=strtok(NULL,"isupper(str)");
}
return 0;
}
#include
#include
using namespace std;
int main() {
// string s;
// getline(cin,s);
char str[1000];
cin>>str;
char *ptr;
ptr=strtok(str,"isupper(str)");
while(ptr!=NULL){
cout<<ptr<<endl;
ptr=strtok(NULL,"isupper(str)");
}
return 0;
}
@vijayuiet1212
First of all , your use of strtok is wrong. When you write “isupper(str)” as the second argument , it does not search for uppercase characters , it simply passes the string “isupper(str)” as the delimiters string .
That is , strtok stops if it find ‘i’ or ‘s’ or ‘u’ or ‘p’ or ‘e’ or ‘r’ or ‘(’ or ‘t’ or ‘)’ .
I believe you may have wanted to pass the capital alphabet as the delimiters.
But even that won’t work as strtok removes the delimiter character from the token. We wish to include the delimiter in out final output as well.
So I suggest you not to use the strtok function.
You can solve this question using a single simple loop.
Just iterate till you hit a capital letter.
If you do , print a new line character - “\n” or otherwise simply go on printing the characters as you read them.
strtok() function is used to make tokens of string ?
@vijayuiet1212
Yes. I suggest you to refer to its documentation here - http://www.cplusplus.com/reference/cstring/strtok/
okey…i got ur point…so only isupper() function shall i use ?
in loop.can i use isupper() function
@vijayuiet1212
Ofcourse , isupper( ) of < cctype > or you can check the old fashion way … using ASCII values.
can u plz send me code…i m not able to solve this.
if(ch >= ‘A’ && ch <= ‘Z’)
i used this condition even then i m not able to get the answer.can u send me code
I cannot share my own code. I can help you out by pointing out modifications in your code though.
if(ch >= ‘A’ && ch <= ‘Z’)
is this a right ? for this problem