Final Output
Part of the Logic & Flow section of Coddy's C journey — lesson 24 of 63.
Challenge
EasyComplete your text utility program by integrating all the features you've built in the previous lessons into a single, comprehensive output. Your program should:
- Prompt the user to enter a short sentence by printing:
Enter a sentence:(no newline at the end — useprintf("Enter a sentence: "), notprintf("Enter a sentence: \n")) - Declare a character array named
sentencewith 200 elements to store the input - Use
scanfwith the%sformat specifier to read a single word from the user - Store the original word in a separate character array for display purposes
- Calculate the total number of characters using
strlen() - 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
- Convert the word to uppercase using
toupper()function in a loop - 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:
HelloYour output should be:
Enter a sentence: Original: Hello
Characters: 5
Vowels: 2
Uppercase: HELLOThis 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
1Pointers Fundamentals
What is a Pointer?Declaring PointersThe Address-Of Operator (&)The Dereference Operator (*)NULL PointersRecap: Pointer Basics4Project: Simple Text Utility
Project OverviewCounting Characters2Pointers and Arrays
Array Names as PointersArray Elements - PointersPointer ArithmeticComparing PointersRecap: Pointer Array Traversal5Pointers and Functions
Pass-by-ValuePassing Pointers to FunctionsModifying Vars via PointersA Classic Example: SwapPassing Arrays to FunctionsRecap: Function Pointer Args8Structs and Pointers
Pointers to StructsThe Arrow Operator (->)Passing Structs by ValuePassing Struct PointersDynamic Allocation of StructsRecap: Modifying Struct - Ptr11Final Recap Challenges
Recap: Dynamic String ConcatRecap: Array of StructsRecap: Word Frequency Counter3Character Arrays and Strings
Strings as char ArraysThe Null TerminatorString Input with scanfUsing strlen()Using strcpy()Using strcat()Using strcmp()Recap: Basic String Functions