Question: Write a C program as follows: Along with stdio.h, you will now include a new header file in your program called string.h (This is because

Write a C program as follows:

Along with stdio.h, you will now include a new header file in your program called string.h (This is because you will use strlen() function).

Declare an enum using typedef and call it Boolean with two values as true and false. You can copy paste the line below in your code: typedef enum boolean {false, true} Boolean;

3. You will write a function called login() of return type Boolean. So place the following function prototype in your code: Boolean login();

4. In the function body, you will do the following:

Declare two string arrays called uname and passwd with max size as 20 or any size you consider appropriate.

Ask the user to enter the username

Ask the user to enter the password

Now using strlen() calculate the length of the password.(Please note: max size of 20 does not mean that the password entered by user will be of length 20. The password can be of any size less than 20 and in order to reverse it using a loop, you need to know the exact length of the password.)

Declare a new variable to store the reverse of the password

Use for loop starting from 0 to the length-1 of the password and use swapping from the password char array to the new char array for the reverse password. ( For example, copy the first letter to last-1 position in the reverse password array, then the second to second last and so on till you reverse the entire password)

Use strcmp() to compare username and password.

If the result of strcmp() is a 0 then they match. So print You are logged in for the user and return 1. Else if the result of strcmp() is non 0 then the username and password do not match. In that case return 0.

5. In your int main(void), you will do the following:

Place a function call for login().

If the value returned by login() is a 0 then set a counter to keep track of the

attempts made by user. You should allow only 3 chances to the user to enter the correct password.

Use a do while loop to ensure that the user gets only 3 attempts.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!