Project Overview
Part of the Logic & Flow section of Coddy's C journey — lesson 20 of 63.
Challenge
EasyOver the next few lessons, you'll build a simple text utility that demonstrates real-world applications of string and character manipulation.
Write a C program that creates the foundation for a text utility by reading and storing user input. Your program should:
- Prompt the user to enter a short sentence by printing:
Enter a sentence: - 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 - Print the stored word in the format:
You entered: [word] - Demonstrate that the character array is properly null-terminated by printing the length of the stored word using
strlen()in the format:Length: [length]
Remember to include the <string.h> header to use the strlen() function.
Your output should display the results in the following format:
Enter a sentence:
You entered: [word]
Length: [length]For example, if the input is:
HelloYour output should be:
Enter a sentence:
You entered: Hello
Length: 5Important: The prompt line must end with a newline immediately after the colon — do not add a trailing space before \n. Use printf("Enter a sentence:\n"); exactly as shown.
This challenge establishes the basic input and storage mechanism that will serve as the foundation for the text utility features you'll add in the upcoming lessons. It tests your understanding of character array declaration, string input with scanf, and basic string length calculation using strlen().
Try it yourself
#include <stdio.h>
#include <string.h>
int main() {
// TODO: Write your code here
// 1. Print the prompt message
// 2. Declare a character array named 'sentence' with 200 elements
// 3. Read input using scanf with %s format specifier
// 4. Print the entered word and its length
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