Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 获取母函数\uuu文件___C - Fatal编程技术网

C 获取母函数\uuu文件__

C 获取母函数\uuu文件__,c,C,我想要的是这样的东西: /client.out:function c.c:78:Error blabla是的,您可以在main.c文件中执行此操作: static const char *executable = NULL; const char *get_main_file() { return executable == NULL ? "????" : executable; } 大体上: int main(...) { executable = argv[0];

我想要的是这样的东西:


/client.out:function c.c:78:Error blabla是的,您可以在
main.c
文件中执行此操作:

static const char *executable = NULL;

const char *get_main_file()
{
    return executable == NULL ? "????" : executable;
}
大体上:

int main(...)
{
    executable = argv[0];
    ...

并从其他文件调用
get\u main\u file()
。这样,
argv[0]
值被导出到任何地方(可能您想对其进行外观更改,对其进行返工以删除完整路径,这可以通过将最后一个路径分隔符的偏移量添加到
可执行文件
(如
basename
does)来轻松完成)

我不想获取导致问题的函数,但要获取主程序的
out:program.c:line
为什么不能将argv[0]传递给函数?它是一个变量,就像任何变量一样other@Jean-Françoisfare我尝试了你的PRETTY_函数和你给出的答案,但它没有返回我所需要的。我编辑了我的帖子,你会understand@ChrisTurner因为在我的应用程序中,我无法通过函数实现我想要的,不确定我是否理解正确,但是如果您想要显示命令名,只需创建静态/全局变量并在main中初始化它。类似于
char*progName=NULL;int main(…){progName=argv[0];…}
int main(...)
{
    executable = argv[0];
    ...