chdir函数用于改变当前进程的目录
getcwd函数用于读取当前进程的路径
这两个函数经常结合使用
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> //改变当前进程打的目录/地址 int main(int argc,char* argv[]){ //判断输入格式 if(argc<2){ printf("./a.out dir"); } int ret= chdir(argv[1]); if(ret ==-1){ perror("chdir"); } //定义缓冲区 char buf[128]; getcwd(buf,sizeof(buf)); //输出修改后当前路径 printf("current path is %sn",buf); return 0; }
结果图
最后
以上就是爱撒娇服饰最近收集整理的关于APUE练习------chdir和chcwd函数的使用的全部内容,更多相关APUE练习------chdir和chcwd函数内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复