当前位置: 技术问答>linux和unix
在C语言中,如何取得程序当前的完整路径?
来源: 互联网 发布时间:2014-12-13
本文导语: 在C语言中,如何取得程序当前的完整路径? 什么函数? | #include char *getcwd(char *buf, size_t size); char *get_current_dir_name(void); char *getwd(char *buf); | #include...
在C语言中,如何取得程序当前的完整路径?
什么函数?
什么函数?
|
#include
char *getcwd(char *buf, size_t size);
char *get_current_dir_name(void);
char *getwd(char *buf);
char *getcwd(char *buf, size_t size);
char *get_current_dir_name(void);
char *getwd(char *buf);
|
#include
#include
int main(int argc, char* argv[])
{
char path[MAXPATH];
getcwd(path, MAXPATH);
printf("当前路径 %s.n", path);
strcat(path, argv[0]);
printf("当前运行程序的完整路径:%sn", path);
}
#include
int main(int argc, char* argv[])
{
char path[MAXPATH];
getcwd(path, MAXPATH);
printf("当前路径 %s.n", path);
strcat(path, argv[0]);
printf("当前运行程序的完整路径:%sn", path);
}
|
#include
#include
#include
#ifndef MAXPATH
const int MAXPATH=1024;
#endif //MAXPATH
int main(int argc, char* argv[])
{
char path[MAXPATH];
getcwd(path, MAXPATH);
printf("Current working directory is %s.n", path);
strncat(path, argv[0], strlen(argv[0]));
printf("Current application path is %s.n", path);
return 0;
}
#include
#include
#ifndef MAXPATH
const int MAXPATH=1024;
#endif //MAXPATH
int main(int argc, char* argv[])
{
char path[MAXPATH];
getcwd(path, MAXPATH);
printf("Current working directory is %s.n", path);
strncat(path, argv[0], strlen(argv[0]));
printf("Current application path is %s.n", path);
return 0;
}