在Linux C中,可以使用getcwd()函数来获取当前工作目录的路径。示例代码:
#include <stdio.h>
#include <unistd.h>
int main() {
char path[1024]; // 存放路径字符串的缓冲区
if (getcwd(path, sizeof(path)) != NULL) {//getcwd函数头文件为<unistd.h>
printf("当前路径为:%s\n", path);
} else {
perror("无法获取当前路径");
return -1;
}
return 0;
}