Camelcase problem

#include
#include

using namespace std;

//Camelcase
int main() {
string s;
getline(cin,s);
int len = s.length();
int i=0,j=0;

while (s[i] != '\0'){
    if (isupper(s[i])){
        for (j=i+1; s[j] != '\0';j++){
            if (isupper(s[j])){
                cout<<s.substr(i,j)<<endl;
                break;
            }
            
        }
        i=j;
                   
    }
    //i+=1;
}
return 0;

}

This code is not giving the correct output. Can you tell what is the error in the code???

Hey @MuskanS
It’d be better that you just write one loop, and whenever you encounter any upper case letters, start adding characters into the new string until the next upper case is encountered or until the string ends and print. Your approach doesn’t print the right ans.

okkayy got it thanks!

1 Like

Hey @MuskanS
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like