0
0
Cprogramming~15 mins

String input and output in C - Mini Project: Build & Apply

Choose your learning style9 modes available
String input and output
📖 Scenario: You are creating a simple program that asks a user for their name and then greets them.
🎯 Goal: Build a program that reads a user's name as input and then prints a greeting message including that name.
📋 What You'll Learn
Use char name[50]; to store the user's name
Use scanf to read the name from input
Use printf to display the greeting message
💡 Why This Matters
🌍 Real World
Reading and displaying text input is a basic skill used in many programs like user registration, chat apps, and command-line tools.
💼 Career
Understanding string input/output in C is essential for system programming, embedded systems, and software development roles.
Progress0 / 4 steps
1
Create a character array to store the name
Declare a character array called name with size 50 to hold the user's name.
C
Need a hint?

Use char name[50]; inside main() to create space for the name.

2
Read the user's name using scanf
Use scanf with "%49s" to read the user's name into the name array.
C
Need a hint?

Use scanf("%49s", name); to safely read a string into name.

3
Print a greeting message with the name
Use printf to display the message Hello, <name>! where <name> is the value stored in name.
C
Need a hint?

Use printf("Hello, %s!\n", name); to show the greeting with the user's name.

4
Run the program and display the greeting
Run the program and enter the name Alice when prompted. The program should print Hello, Alice!.
C
Need a hint?

Type Alice as input and check that the output is Hello, Alice!