Challenge: Title Case

Lab C Intermediate 20 points

Read one line of words separated by single spaces and print it with the first letter of every word in capitals and all other letters small.

Input

One line of text.

Output

The same line in Title Case.

Example

Input

hello world

Output

Hello World
Sample input available Sample output available
Editor
C

Hints

A letter starts a word if it is the first character or comes after a space.

Use toupper for word starts and tolower for everything else.

Solution explanation

We look at the character before each letter to decide whether it begins a new word.

Show solution
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
    char line[201];
    fgets(line, 201, stdin);
    line[strcspn(line, "\n")] = '\0';
    for (int i = 0; line[i] != '\0'; i++) {
        if (i == 0 || line[i - 1] == ' ') {
            line[i] = toupper(line[i]);
        } else {
            line[i] = tolower(line[i]);
        }
    }
    printf("%s\n", line);
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD