Hi All!
I'm trying to get this code to work where when I type a string in, it will take the first character of each word and make it uppercase and the rest lower case-- I can't get it to work- I got it to go all uppercase?!!! How to get it so it only takes the first character to uppercase and rest lower? Any ideas?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
char line[40];
char *pc;
int length;
while(1)
{
if(gets(line) == NULL)
{
printf("End of file encountered.\n");
break;
}
if (strcmp(line, "quit") == 0)
{
printf("Good bye!\n");
break;
}
length = strlen(line);
for (pc = line; pc - line < length; pc++)
{
putchar(toupper(*pc));
}
putchar('\n');
}
return 0;
}
I'm trying to get this code to work where when I type a string in, it will take the first character of each word and make it uppercase and the rest lower case-- I can't get it to work- I got it to go all uppercase?!!! How to get it so it only takes the first character to uppercase and rest lower? Any ideas?
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
char line[40];
char *pc;
int length;
while(1)
{
if(gets(line) == NULL)
{
printf("End of file encountered.\n");
break;
}
if (strcmp(line, "quit") == 0)
{
printf("Good bye!\n");
break;
}
length = strlen(line);
for (pc = line; pc - line < length; pc++)
{
putchar(toupper(*pc));
}
putchar('\n');
}
return 0;
}