Title Case
Completed
Read a line and capitalise the first letter of every word, lower-casing the rest.
Input
One line.
Output
One line.
Example
Input
hELLO wORLD from c
Output
Hello World From C
Editor
C
Hints
Remember whether the previous character was a space.
Solution explanation
A single flag is enough to know where words start.
Show solution
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char s[300];
fgets(s, 300, stdin);
s[strcspn(s, "\n")] = '\0';
int start = 1;
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] == ' ') {
start = 1;
} else if (start) {
s[i] = toupper(s[i]);
start = 0;
} else {
s[i] = tolower(s[i]);
}
}
printf("%s\n", s);
return 0;
}