Syntax
#include <direct.h> char *_getcwd(char *pathbuf, int n);Description
If the pathbuf argument is NULL, _getcwd 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 _getcwd return value as the argument to free.
Value
This example stores the name of the current working directory (up to _MAX_PATH characters) in a buffer. The value of _MAX_PATH is defined in <stdlib.h>.
#include <direct.h>#include <stdio.h> #include <stdlib.h> int main(void) { char buffer[_MAX_PATH]; if (NULL == getcwd(buffer, _MAX_PATH)) perror("getcwd error"); printf("The current directory is %s.\n", buffer); return 0; /**************************************************************************** The output should be similar to: The current directory is E:\C_OS2\MIG_XMPS ****************************************************************************/ }Related Information