I need some help on creating a function similar to the putenv() function of the C standard library, but instead of:
int putenv(char *string);
it is prototyped as:
void env_add(char varname[], char varvalue[]);
where varname[] and varvalue[] are entered by the user and are of type char.
You should measure the length of
varnameandvarvalue(with e.g.strlen), allocate dynamically a string long enough to hold them, the equal sign and the null terminator, build thevarname=varvaluestring (you can do that with e.g.snprintforstrncat, or with twoforloops if you are the masochist type), pass the new string toputenvand deallocate the string you’ve built.By the way, I’d change the type of
varnameandvarvaluetoconst char *, because in your function you are not actually modifying them.