Write the C function int camelCase(char * text) to transform any string made of words separated by spaces in CamelCase format, that is, converting to uppercase the first character of all words, converting all remaining characters of a word to lowercase and removing all spaces .
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char str[100];
printf("Input a string: ");
do
{
& gets(str);
} while(!str[0]);
camelCase(str);
printf("String in camelCase: %s",str);
return 0;
}
int camelCase(char *text)
{
int i;
char *p;
char str[100] = "";
p = strtok(text," ");
while (p != NULL)
{
& p[0] = toupper(p[0]);
& for (i=1;p[i];i++)
& {
p[i] = tolower(p[i]);
& }
& strcat(str,p);
& p = strtok(NULL," ");
}
strcpy(text,str);
text[0] = tolower(text[0]);
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C#