函数getcwd()
char* _getcwd( char *buffer, int maxlen );
// 功 能 : 获得当前工作目录.
// 头文件 : #include <direct.h>
// 返回值 : 成功返回指向buffer的pointer
// 失败返回NULL,且设置errno为以下三个值之一:
// ENODEV 无该设备
// ENOMEM 内存不够
// ERANGE 结果超出范围
// 注 意 : 当第一个参数为 NULL 时, 第二个参数 maxlen 长度设置无效,且函数
// 使用 malloc 分配足够内存, 需要将函数返回值传递给 free() 函数来
// 释放内存. 当第一个参数不为 NULL 时,maxlen 指定长度不够函数返回
// 错,设置errno为ERANGE
示例
#include <stdio.h>
#include <direct.h>
#define MAXPATH 1024
int main()
{
char buffer[MAXPATH];
_getcwd(buffer,MAXPATH);
printf("%s",buffer);
return 0;
}