getcwd函数学习

getcwd
函数原型:char *getcwd( char *buffer, int maxlen );
功 能:获取当前工作目录
参数说明:getcwd()会将当前工作目录的绝对路径复制到参数buffer所指的内存空间中,参数maxlen为buffer的空间大小。
返 回 值:成功则返回当前工作目录,失败返回 FALSE。
在某些 Unix 的变种下,如果任何父目录没有设定可读或搜索模式,即使当前目录设定了,getcwd()还是会返回 FALSE。有关模式与权限的更多信息见 chmod()。
头文件:unistd.h(windows下为direct.h)

  1. #include <unistd.h>
  2. #include <stdio.h>

  3. #define MAXPATH 1024

  4. int main(void)
  5. {
  6.     char buffer[MAXPATH];
  7.     getcwd(buffer, MAXPATH);
  8.     printf("The Current directory is :%s ", buffer);

  9.     return 0;
  10. }

无欲速,无见小利。欲速,则不达;见小利,则大事不成。
原文地址:https://www.cnblogs.com/ch122633/p/7363244.html