Question
A user wants a C program that will indicate whether its argument is a valid integer or not. The program, called isint, accepts one argument.
A user wants a C program that will indicate whether its argument is a valid integer or not. The program, called isint, accepts one argument. If the argument is a string that contains only numeric characters, optionally preceded by a '-' or '+' character, the program exits indicating success. Otherwise the program exits indicating failure (false). The program also exits with failure if the value of the argument is 0 and it is preceded by a '-' or '+' character (since zero is neither positive or negative). The program can also take an optional argument, -p, which requires that the integer be positive for successful termination. For instance, the program will exit-with-success in the following cases: isint 2345 isint -2345 isint 0 isint +2 isint -p 2345 inint -p +1 However, the program will terminate with a non-zero exit status for: isint d345 isint -2d45 isint +2d isint -p -2345 isint -p 00 Design, implement, test, and document such a program. The program does not generate any output, either on stdin or stderr. To see the result of the program, output the value of the shell variable ? after executing the command. (The $ shell variable contains the exit status of the last program executed.) For example, you could exercise the program in the following way: bash-4.3$ isint 000 bash-4.3$ echo $? 0 bash-4.3$ isint -p "2 3" bash-4.3$ echo $? 1 bash-4.3$ where "bash-4.3$ " is the bash shell prompt. Use filenames beginning with q2 for your annotated test log and program documentation. Submit them and your isint.c file as your solution to this question. Notes: You may find the man page for isdigit(3) of use. Even though the program takes few options and arguments, students may find it useful to consider using the functions in getopt(3). The above example uses an exit value (by isint) of 1 for a failing case. You can use any other non-zero value instead.
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