include include include include include Simple example of u
#include
#include
#include
#include
#include
/* Simple example of using gnu readline to get lines of input from a user. Needs to be linked with -lreadline -lcurses
add_history tells the readline library to add the line to it\'s
internal history, so that using up-arrow (or ^p) will allows the user to see/edit previous lines.
*/
int main(int argc, char **argv)
{
char *s;
while (s=readline(\"prompt> \"))
{
add_history(s); /* adds the line to the readline history buffer */
free(s); /* clean up! */
}
return(0);
Directions: Complete Task 2 (code in C)
Task 2: Environment Variables - (20 points) Every Unix process uses/includes an array of strings called the \"environment.\" Each of these strings is of the form \"name-value\" (This is by convention. There is no requirement that every string in the environment be of this form). There are various functions available for accessing these strings by the \"name\" contained in each one. These name/value pairs are referred to as environment variables. Below is a list of some of the functions you can use to access/manipulate these environment variables: setenv, putenv: change/set the value of a variable given the name. getenv: get the value of an environment variable given the name. . unsetenv: remove an environment variable. There is also a global variable named environ that can be used to access the environment strings. For the details on any of the above, use the unix man command (\"man environ\" or \"man setenv\", ...) You are to extend the code that you wrote in Task 1 so that it reads and executes the following commands: · set varname = somevalue: set the value of the environment variable named varname to the value specified by somevalue. . delete varname: remove the named environment variable. · print varname: prints out the current value of the named environment variable.Solution
#include <stdio.h>
#include <stdlib.h>
int main()
{
// set Env Varaible PATH some value
setenv(\"PATH\", \"New Value\", 1);
// get value pf Env Variable \"PATH\"
char* value = getenv(\"PATH\");
if(value)
{
printf(\"variable %s has value %s \ \",value);
}
else
printf(\"variable %s has no value \ \");
}

