Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

ou 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.

If your main function is called main.c compile as follows:

gcc -o main main.c parse.c

Test your program thoroughly. Then, once you are convinced that it works, assess it as follows:

put your function in a file named parse.c There should not be a main function in parse.c: it should only contain your function.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

What are the major effects of unions on compensation?

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago