Originally Posted by
cprogrammer1980
should I do this using an 'if' statement?
Code:
int strCase(char s[])
{
int i=0;
while (s[i])
{
s[i] = toupper(s[i]);
i++;
}
return 0;
}
this is what I have so far I am toying around with making it all CAPS, the code compiles but it isnt converting them for some reason
This is UNTESTED code. It's only to show concept...
Code:
void strcase(char *str)
{ int x, y; // loop variables
char *ucp; // upper case pointer
y = strlen(str);
// convert to all lower case
for( x = 0; x < y; x++)
{ str[x] = tolower(str[x]); }
// capitalize words
ucp = str;
while (ucp = strchr(ucp,' '))
{ ++ ucp;
*ucp = toupper(*ucp);} }
Of course this won't work if there are multiple spaces between words... but removing them is a whole other problem.