Question: Objectives Write a small program that uses both short and long options from getopt _ long ( ) . Use sscanf ( ) or strtof
Objectives
Write a small program that uses both short and long options from getoptlong
Use sscanf or strtofstrtol for converting a string representation of a value into the numeric value.
Use the rand function.
Use the strncpy function. The maximum length of the string will be characters not including the trailing NULL You must create either a #define to represent this value or a const variable.
The command line arguments your program must take are:
Command line option Description:
h or help Print the usage information. Your output should look like the example I show in this document.
r or rand Print the pseudorandom number returned from a call to rand The values printed by your program may differ from the ones I show. Don't seed your random number. This means it should print the same set of random numbers. That's just how pseudorandom number generators work.
f or float Take the string value that follows the option convert it into a float data type, divide it by and print the result.
i or int Take the string value that follows the option convert it into a int data type, add to it and print the result.
s or str Take the string value passed, print it convert all the characters in it to upper case, and print the upper case version of the string. If you pass a string that includes spaces someplace in it you'll need to put quotes around the entire string. Think about the toupper function. I have a strong feeling that you are going to somehow make a copy of the string from the command line.
Example output:
Below are some sample output results when running my solution. Your output should match mine for these examples:
Username # getoptlong h
This is a help message:
floatf
inti
strs
randr
helph
Usernamegetoptlong help
This is a help message:
floatf
inti
strs
randr
helph
Usernamegetoptlong i int iint
int value :
int value :
int value :
int value :
Usernamegetoptlong f ffloat float
float value :
float value :
float value :
float value :
Usernamegetoptlong s hello shello world" str "hello there" str"hello it's me
orig: helloupcase: HELLO
orig: hello worldupcase: HELLO WORLD
orig: hello thereupcase: HELLO THERE
orig: hello it's meupcase: HELLO IT'S ME
Usernamegetoptlong r rand
random value
random value
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
