版本1:
调用系统接口getcwd,实现路径打印。
/*
**
***文件名:1_mypwd.c
***描述:通过系统函数getcwd实现pwd命令
**
*/
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
char buf[1024];
char *cwd = getcwd(buf,sizeof(buf));
if (NULL == cwd)
{
perror("Get current working directory fail.n");
exit(-1);
}
else
{
printf("Current working directory is : %sn",cwd);
}
return0;
}
实验结果:
原文:https://www.cnblogs.com/wanghao-boke/p/11776817.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!