0
0
Cprogramming~30 mins

Using return codes - Mini Project: Build & Apply

Choose your learning style9 modes available
Using return codes
📖 Scenario: You are writing a small program that simulates a simple login system. The program checks if a username and password are correct and returns a code to indicate success or failure.
🎯 Goal: Build a C program that uses return codes from a function to indicate if login was successful or not.
📋 What You'll Learn
Create a function that checks username and password and returns 0 for success and 1 for failure
Use variables to store the correct username and password
Call the function with test username and password
Print the return code to show if login succeeded or failed
💡 Why This Matters
🌍 Real World
Return codes are used in many programs to signal if an operation succeeded or failed, like login systems, file operations, or network requests.
💼 Career
Understanding return codes helps in debugging and writing clear, maintainable code that communicates status between functions and modules.
Progress0 / 4 steps
1
Create variables for correct username and password
Create two char arrays called correct_username and correct_password with values "admin" and "1234" respectively.
C
Need a hint?

Use char arrays to store text strings in C.

2
Create a function to check login and return codes
Write a function called check_login that takes two char* parameters named username and password. The function should return 0 if both match correct_username and correct_password, otherwise return 1.
C
Need a hint?

Use strcmp from string.h to compare strings. Return 0 for success, 1 for failure.

3
Call the function with test values
Create two char* variables called test_user and test_pass with values "admin" and "1234". Then call check_login(test_user, test_pass) and store the result in an int variable called result.
C
Need a hint?

Use string pointers for test username and password. Store the function return in result.

4
Print the return code result
Write a printf statement to print "Login result: %d\n" with the variable result.
C
Need a hint?

Use printf to show the login result number.