首页 > 应用开发 > > getcwd函数学习
getcwd
函数原型:char *getcwd( char *buffer, int maxlen );
功 能:获取当前工作目录
参数说明:getcwd()会将当前工作目录的绝对路径复制到参数buffer所指的内存空间中,参数maxlen为buffer的空间大小。
返 回 值:成功则返回当前工作目录,失败返回 FALSE。
在某些 Unix 的变种下,如果任何父目录没有设定可读或搜索模式,即使当前目录设定了,getcwd()还是会返回 FALSE。有关模式与权限的更多信息见 chmod()。
头文件:unistd.h(windows下为direct.h)
#include <unistd.h>
#include <stdio.h>
#define MAXPATH 1024
int main(void)
{
char buffer[MAXPATH];
getcwd(buffer, MAXPATH);
printf("The Current directory is :%s\n", buffer);
return 0;
}来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2508/viewspace-3138190/ ,如需转载,请注明出处,否则将追究法律责任。