/*///////////////////////////////////////////////////////// // demo executable // // Takes a list of environment variable names as // command-line arguments, and prints them with // their values to a file named "env-vars" in the // current directory. // // Example code by Albert L. Rossi, IU Extreme! Computing // December 2001 /////////////////////////////////////////////////////////*/ #include #include int main (int argc, char **argv) { FILE *list; char *value; char nd [10]; int i; if ((list = fopen("env-vars", "w")) == NULL) { fprintf(stderr, "could not open env-vars\n"); return -1; } sprintf(nd, "%s", "Undefined"); for (i = 1; i < argc; i++) { if ((value = getenv(argv[i])) == NULL) value = nd; fprintf(list, "%s:\t%s\n", argv[i], value); } fclose(list); return 0; }