0
0
Cprogramming~15 mins

String comparison - Mini Project: Build & Apply

Choose your learning style9 modes available
String comparison
📖 Scenario: You are creating a simple program to compare two words typed by a user. This is like checking if two names or passwords are exactly the same.
🎯 Goal: Build a program that reads two strings and tells if they are the same or different using string comparison.
📋 What You'll Learn
Use char arrays to store the two strings
Use strcmp function to compare the strings
Print "Strings are equal" if they match exactly
Print "Strings are different" if they do not match
💡 Why This Matters
🌍 Real World
String comparison is used in many programs to check passwords, search for words, or match user input exactly.
💼 Career
Understanding string comparison is important for software development, especially in input validation, data processing, and user authentication.
Progress0 / 4 steps
1
Create two string variables
Create two char arrays called str1 and str2 each with size 20.
C
Need a hint?

Use char str1[20]; and char str2[20]; to create the string variables.

2
Read two strings from the user
Use scanf to read input into str1 and str2.
C
Need a hint?

Use scanf("%19s", str1); and scanf("%19s", str2); to read the strings safely.

3
Compare the two strings
Use strcmp(str1, str2) to compare the strings and store the result in an int variable called result.
C
Need a hint?

Use int result = strcmp(str1, str2); to compare the strings.

4
Print if strings are equal or different
Use an if statement to check if result is 0. If yes, print "Strings are equal". Otherwise, print "Strings are different".
C
Need a hint?

Use if (result == 0) to check equality and printf to show the messages.