Answer to Question #12496 in C# for Nora

Question #12496
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 .
1
Expert's answer
2012-08-09T08:41:24-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS