gpt4 book ai didi

c - 段错误回溯到 vfprintf?

转载 作者:行者123 更新时间:2023-12-01 22:43:35 26 4
gpt4 key购买 nike

我遇到段错误并使用 gdb 和回溯,它在 vprintf 处抛出。

#0  0x006e8779 in vfprintf () from /lib/libc.so.6
#1 0x006f265f in fprintf () from /lib/libc.so.6
#2 0x08049fd1 in write_tofile (logfile=0x9843090 "~/www/log") at example.c:446

它发生在我打电话的时候

file = fopen(log_file, "a"); // log_file = "~/www/log"
fprintf(file, buffer);

fopen 可以处理来自不同目录的文件吗?有人知道它为什么会在这里出现段错误吗?

最佳答案

使用 '~' 作为你的主目录的缩写是一个 shell 的东西,在 C 中不一定可用。这可能会导致 fopen失败,并且您没有检查返回码。

关于c - 段错误回溯到 vfprintf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9443432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com