Syntax
#include <direct.h> char *_getdcwd(int drive, char *pathbuf, int n);Description
The integer argument n specifies the maximum length for the path name. An error occurs if the length of the path name, including the terminating null character, exceeds n characters.
If the pathbuf argument is NULL, _getdcwd uses malloc to reserve a buffer of at least n bytes to store the path name. If the current working directory string is more than n bytes, a large enough buffer will be allocated to contain the string. You can later free this buffer using the _getdcwd return value as the argument to free.
Alternatives to this function are the DosQueryCurrentDir and DosQueryCurrentDisk functions.
Value
This example uses _getdcwd to obtain the current working directory of drive C.
#include <stdio.h>#include <direct.h>
#include <errno.h>
int main(void)
{
   char *retBuffer;
   retBuffer = _getdcwd(3, NULL, 0);
   if (NULL == retBuffer)
      printf("An error has occurred, errno is set to %d.\n", errno);
   else
      printf("%s is the current working directory in drive C.\n", retBuffer);
   return 0;
   /****************************************************************************
      The output should be similar to:
      C:\ is the current working directory in drive C.
   ****************************************************************************/
}
Related Information