Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this problem, the following C library functions can be used, but no others: printf, sprintf, strcmp, atoi, sizeof, malloc, and free. Write a program
For this problem, the following C library functions can be used, but no others: printf, sprintf, strcmp, atoi, sizeof, malloc, and free. Write a program that does the following:
- Takes the following command-line arguments from the user: a secret code, a first name, a last name, and one or more whole numbers.
- If the user doesn't give a sufficient number of command-line arguments, output "Invalid input" and terminate.
- If the user doesn't give the correct secret code, output "Incorrect secret code" and terminate. The correct secret code is: hHFmas. (Hint: strcmp returns 0 if the two string arguments match.)
- Store the first and last name in a string variable called fullName, with a space between the first and last name. (Hint: Use sprintf.)
- You must use malloc to allocate sufficient memory for the fullName variable, and deallocate that memory before program termination.
- Output fullName and the average of the numbers on the command line. The average must be accurate to 1 decimal place.
- The program must work for names of any length and an arbitrary amount of numbers on the command line.
Please help asap!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started