C - Unsetting an environment variable

12. March 2012 08:00

 

A short example to in C to clear an enviroment variable using the libc function unsetenv

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv) {

	if (unsetenv("HOME") < 0) {
		perror("unsetenv");
		exit(EXIT_FAILURE);
	}

	system("env | grep HOME");
	return 0;
}

E-mail Kick it! DZone it! del.icio.us Permalink