文件IO-getcwd-chdir
作者:互联网
chdir
getcwd
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define MAX 512
int main(int argc, char * argv[])
{
// 方法一
char path[MAX];
path[0] = '\0';
getcwd(path, sizeof(path));
puts(path);
// 改变路径
if (chdir("/home") < 0)
{
perror("Error chdir.\n");
exit(EXIT_FAILURE);
}
// 方法二
char * buf = NULL;
buf = getcwd(NULL, 0);
puts(buf);
free(buf);
exit(EXIT_SUCCESS);
}
标签:chdir,getcwd,char,IO,path,include,buf 来源: https://www.cnblogs.com/starc/p/16615563.html