Question: you need to write a C function named parse. The prototype is: int parse(char *); The function accepts a string; scans it with sscanf to

you need to write a C function named parse. The prototype is:

int parse(char *);

The function accepts a string; scans it with sscanf to try to convert it to an integer; and returns a value as follows:

if the integer=1, return 1 if the integer=2, return 2 if the integer=3, return 3 in all other cases, return -1

This means if the string is empty, if it starts with a non-digit, if it's an integer bigger than 3 or less than 1, if it has non-printabe characters, etc. then your function should return -1. Use sscanf to do the conversion. If sscanf can convert it to an integer, use that integer value and make sure it's between 1 and 3. If sscanf can't convert it to an integer, return -1.

Write your own main test function to test your parse function. Test it however you see fit: you can hardwire values, input values while your program runs, use command line parameters, of whatever else makes sense to you.

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!