Well, i dint wanted to give you the whole code. You will have to sit down and go through the problem again and again. You have already got lots of suggestion from many other members. Although just to give you a brief idea, i mean an alternative idea on how to approach this problem. Look at the following code
Code:
ptr = strtok( str, " " );
while( ptr != NULL )
{
strcat( result, toTitleCase( ptr ) );
strcat( result, " ");
ptr = strtok( NULL, " " );
}
Well, the main objective of the problem is to capitalize the char in a given word. Lets keep things simple here. An alternative way to approach is to token the string you get each word. You know that in each word the first char should be capital. Sent that word to some user defined function which changes the first char in that word to capital and the lower cases the rest of the chars in the word and return that string back to the calling function. And returned string will .be concatenated to a resultant string. May be i can provided that user defined function. But you should work with the rest.
Code:
const char *toTitleCase( char *token )
{
int i;
token[0] = toupper( token [0] );
for( i = 1; token[i] != '\0'; i++ )
token[i] = tolower( token[i] );
return token;
}
If this donst help, then you should really look back and go through some basics again!!
ssharish