Write a program to display the value of the environment variables set for your shell. You can display these using the UNIX command: rcm$ env Your program will display them differently (i.e., sorted by variable name) and will also involve using the getenv(3) and malloc(3) functions. In your program declare an extern char **environ (see the text section 7.5). Use this to count the number of entries defined in the environment. Next malloc an array big enough to contain count character pointers. Copy the environment’s character pointers into this malloc’ed array. Using the copied array, sort the strings in alphabetically ascending order (use the ASCII collating sequence, and strcmp(3) to determine when one string is alphabetically greater than another). If you still have your code from CMPSC 121/IST 140, use either the bubble sort or selection sort you did in that class to sort the copied array; do NOT sort the environment itself as any program logic errors will wreak havoc with your program’s environment! Depending on the value of an environment variable, FORMAT, you will then display the sorted contents of the environment in either name-value order or value-name order. When the FORMAT environment variable is set to REVERSE print out the environment in value-name order; if it is set to anything else OR not set, print out the environment in name-value order. You will need to parse the strings in the environment separating the name and value on either side of the equal sign (=). Do not try to use sscanf(3) to do this as sscanf expects to see white space between strings! You will need to write your own parsing function. You set an environment variable with the command line: rcm$ export FORMAT=REVERSE And you unset an environment variable with the command line: rcm$ export FORMAT= Lastly, you display the value of an environment variable with the command line: rcm$ echo $FORMAT Here are two abbreviated examples of the output expected; in name-value order: name: Apple_PubSub_Socket_Render , value: /tmp/launch-DU1xCd/Render name: EDITOR , value: vi name: FORMAT , value: name: HOME , value: /Users/rcm name: LANG , value: en_US.UTF-8 name: LOGNAME , value: rcm name: OLDPWD , value: /Users/rcm/CMPSC311/rcm/exercises . . . And in value-name order: value: /tmp/launch-DU1xCd/Render , name: Apple_PubSub_Socket_Render value: vi , name: EDITOR value: REVERSE , name: FORMAT value: /Users/rcm , name: HOME value: en_US.UTF-8 , name: LANG value: rcm , name: LOGNAME value: /Users/rcm/CMPSC311/rcm/exercises, name: OLDPWD . . . I used field widths of 32 characters (i.e., with %-32s); you are not expected to get everything lined up perfectly. Note that the value of the _ environment variable is set one way when using the env command, and set another way when you execute your program.
https://trustedpaperwriters.com/wp-content/uploads/2019/12/157544039158860773-300x54.png 0 0 Steve Kamau https://trustedpaperwriters.com/wp-content/uploads/2019/12/157544039158860773-300x54.png Steve Kamau2021-07-23 22:25:212021-07-23 22:25:21Write a program to display the value of the environment variables set for your shell. You can displa