C Write a function that takes a Cstring char pointer as an a

C++:

Write a function that takes a C-string (char pointer) as an argument. The c-string is a sentence where all of the words run together (no spaces), but each word is capitalized. Convert the C-String such that there are spaces between each word and only the first word in the sentence is capitalized. Note: Use of C-String functions is important here!

Example: \"It\'sDangerousToGoAlone!\" becomes \"It\'s dangerous to go alone!\"

Solution

This function can be used:

#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
void changeString(char *c)
{
int l=strlen(c),i,j;
char a[l];
strcpy(a,c);
for(i=0,j=0;i<l;i++){
if(i!=0 && isupper(a[i])){
c[j++]=\' \';
c[j++]=tolower(a[i]);
}else{
c[j++]=a[i];
}
}
c[j]=\'\\0\';
}
int main() {
   // your code goes here
   char str[]=\"It\'sRainingOutThere\";
   changeString(str);
   cout<<\"New String is:\"<<str;
   return 0;
}

C++: Write a function that takes a C-string (char pointer) as an argument. The c-string is a sentence where all of the words run together (no spaces), but each

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site