C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
ENVIRON.C
◄Up► ◄Contents► ◄Index► ◄Back►
─────Run-Time Library───────────────────────────────────────────────────────
/* ENVIRON.C illustrates environment variable functions including:
* getenv _putenv _searchenv
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void main( void )
{
char *pathvar, pathbuf[256], filebuf[256];
/* Get the PATH environment variable and save a copy of it. */
pathvar = getenv( "PATH" );
strcpy( pathbuf, pathvar );
printf( "Old PATH: %s\n", pathvar ? pathvar : "variable not set");
/* Add a new directory to the path. */
strcpy( pathbuf, "PATH=" );
strcat( pathbuf, pathvar );
strcat( pathbuf, ";\\C700\\INIT;" );
if( _putenv( pathbuf ) == -1 )
{
printf( "Failed\n");
exit( 1 );
}
else
printf( "New PATH: %s\n", pathbuf );
/* Search for file in the new path. */
_searchenv( "TOOLS.INI", "PATH", filebuf );
if( *filebuf )
printf( "TOOLS.INI found at %s\n", filebuf );
else
printf( "TOOLS.INI not found\n" );
/* Restore original path. */
strcpy( pathbuf, "PATH=" );
strcat( pathbuf, pathvar );
if( _putenv( pathbuf ) == -1 )
printf( "Failed\n");
else
printf( "Old PATH: %s\n", pathvar );
exit( 0 );
}
-♦-