_pgmptr, _wpgmptr

When a program is run from the command interpreter (CMD.EXE), _pgmptr is automatically initialized to the full path of the executable file. For example, if HELLO.EXE is in C:\BIN and C:\BIN is in the path, _pgmptr is set to C:\BIN\HELLO.EXE when you execute

C> hello 

When a program is not run from the command line, _pgmptr may be initialized to the program name (the file’s base name without the extension), or to a filename, a relative path, or a full path.

_wpgmptr is the wide-character counterpart of _pgmptr for use with programs that use wmain. _pgmptr and _wpgmptr are declared in STDLIB.H as

extern char *_pgmptr;

extern wchar_t *_pgmptr;

The following program demonstrates the use of _pgmptr.

/* 
 * PGMPTR.C: The following program demonstrates the use of _pgmptr.
 */

#include <stdio.h>
#include <stdlib.h>
void main( void )
{
   printf("The full path of the executing program is : %Fs\n", 
     _pgmptr);
}