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 getopt_long().
Use sscanf() or strtof()/strtol() 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 99 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:
1)-h or --help Print the usage information. Your output should look like the example I show in this document.
2)-r or --rand Print the pseudo-random 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 pseudo-random number generators work.
3)-f or --float Take the string value that follows the option () convert it into a float data type, divide it by 10, and print the result.
4)-i or --int Take the string value that follows the option () convert it into a int data type, add 100 to it, and print the result.
5)-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:
1)(Username) # ./getopt-long -h
This is a help message:
--float|-f
--int|-i
--str|-s
--rand|-r
--help|-h
2)(Username)./getopt-long --help
This is a help message:
--float|-f
--int|-i
--str|-s
--rand|-r
--help|-h
3)(Username)./getopt-long -i 17--int 23-i8--int=34
int value +100: 117
int value +100: 123
int value +100: 108
int value +100: 134
4)(Username)./getopt-long -f 37.5-f38.5--float 380.5--float=375.2
float value /10: 3.750000
float value /10: 3.850000
float value /10: 38.050000
float value /10: 37.520001
5)(Username)./getopt-long -s hello -s"hello world" --str "hello there" --str="hello it's me"
orig: >hello<upcase: >HELLO<
orig: >hello world<upcase: >HELLO WORLD<
orig: >hello there<upcase: >HELLO THERE<
orig: >hello it's me<upcase: >HELLO IT'S ME<
6)(Username)./getopt-long -r --rand
random value =1804289383
random value =846930886

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 Programming Questions!