3.9 _pgmptr

The _pgmptr variable is automatically initialized at startup to point to the full path of the executing program. It is defined as a global variable in the run-time library and declared in CRT0DAT.ASM, which is part of the startup code. This code is linked to any module that contains a main function. Declaring _pgmptr in your own code is all that is required to make the full path available to your program:

extern char __far *_pgmptr;

The following program demonstrates the use of _pgmptr:

#include <stdio.h>

extern char __far *_pgmptr;

void main( void )

{

printf("The full path of the executing program is : %Fs\n",

_pgmptr);

}

In DOS versions 3.0 and later, argv[0] also contains a pointer to the full path of the executing program.