0
0
Cprogramming~30 mins

Character arrays - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Character Arrays in C
📖 Scenario: You are creating a simple program that stores and displays a name using character arrays in C. This is like writing a name on a piece of paper and then reading it out loud.
🎯 Goal: Build a program that stores a name in a character array, counts the number of characters, and then prints the name and its length.
📋 What You'll Learn
Create a character array with a specific name
Create an integer variable to store the length of the name
Use a loop to count the characters in the array
Print the name and the length
💡 Why This Matters
🌍 Real World
Character arrays are used to store text like names, messages, or any words in many programs.
💼 Career
Understanding how to work with strings and arrays is essential for programming in C, especially in systems programming and embedded software.
Progress0 / 4 steps
1
Create a character array with the name
Create a character array called name and initialize it with the string "Alice".
C
Need a hint?

Use double quotes to create a string in C, like char name[] = "Alice";.

2
Create an integer variable for length
Create an integer variable called length and set it to 0.
C
Need a hint?

Use int length = 0; to create the variable.

3
Count the characters in the array
Use a for loop with an integer variable i starting at 0 to count characters in name until you find the null character '\0'. Increase length by 1 for each character.
C
Need a hint?

Use name[i] != '\0' to check for the end of the string.

4
Print the name and its length
Use printf to print the text Name: followed by the name array, then print Length: followed by the length variable on the next line.
C
Need a hint?

Use printf("Name: %s\n", name); and printf("Length: %d\n", length);.