Menu
Coddy logo textTech

Final Output

Part of the Logic & Flow section of Coddy's C journey — lesson 24 of 63.

challenge icon

Challenge

Easy

Complete your text utility program by integrating all the features you've built in the previous lessons into a single, comprehensive output. Your program should:

  1. Prompt the user to enter a short sentence by printing: Enter a sentence: (no newline at the end — use printf("Enter a sentence: "), not printf("Enter a sentence: \n"))
  2. Declare a character array named sentence with 200 elements to store the input
  3. Use scanf with the %s format specifier to read a single word from the user
  4. Store the original word in a separate character array for display purposes
  5. Calculate the total number of characters using strlen()
  6. Count the vowels by iterating through each character and checking if it matches any vowel (a, e, i, o, u) in both lowercase and uppercase
  7. Convert the word to uppercase using toupper() function in a loop
  8. Display all results in a clean, organized format with each piece of information on a separate line

Remember to include the <string.h> header for string functions and the <ctype.h> header for character conversion functions.

Your output should display all results in the following exact format:

Enter a sentence: Original: [word]
Characters: [count]
Vowels: [count]
Uppercase: [WORD]

Important: The prompt Enter a sentence: must not be followed by a newline. The word Original: appears on the same line immediately after the input is read.

For example, if the input is:

Hello

Your output should be:

Enter a sentence: Original: Hello
Characters: 5
Vowels: 2
Uppercase: HELLO

This final challenge brings together all the text processing features you've developed throughout the project: input handling, character counting with strlen(), vowel counting with loops and conditional statements, and uppercase conversion with toupper(). The program should present a clean, organized summary of the text analysis results.

Try it yourself

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

int main() {
    char sentence[200];
    
    printf("Enter a sentence: ");
    scanf("%s", sentence);
    
    printf("You entered: %s\n", sentence);
    
    int length = strlen(sentence);
    printf("Character count: %d\n", length);
    printf("Length: %d\n", length);
    
    int vowel_count = 0;
    for (int i = 0; i < length; i++) {
        char c = sentence[i];
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
            c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
            vowel_count++;
        }
    }
    printf("Vowel count: %d\n", vowel_count);
    
    printf("Uppercase: ");
    for (int i = 0; i < length; i++) {
        printf("%c", toupper(sentence[i]));
    }
    printf("\n");
    
    return 0;
}

All lessons in Logic & Flow