c - 段错误 : 1902 vfscanf. c: 没有这样的文件或目录

标签 c segmentation-fault gdb

程序因 scanf() 函数出现段错误而停止。 这是简化的代码:

int main() {
  int x = 0;
  printf("$ ");
  scanf("%i", x);

  return 0;
}

当我使用 gdb 运行此命令时,我收到以下消息:

(gdb) run
Starting program: /home/siery/dev/shell/classes/bin/Recure 

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff71f6794 in _IO_vfscanf_internal (s=<optimized out>, format=<optimized out>, argptr=argptr@entry=0x7fffffffe608, errp=errp@entry=0x0) at vfscanf.c:1902
1902    vfscanf.c: No such file or directory.

我尝试在互联网上搜索 vfscanf.c,但没有找到太多有用的信息。

顺便说一句。我用g++编译这个程序,g++是新更新的,与gdb相同。

最佳答案

scanf("%i", &x);
//          ^ THIS IS THE IMPORTANT BIT

gcc 甚至告诉你这一点:

foo.c: In function ‘main’:
foo.c:6:9: warning: format ‘%i’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=]
   scanf("%i", x);
         ^

vfscanf.c:没有这样的文件或目录只是gdb提示它找不到scanf的源代码。

关于c - 段错误 : 1902 vfscanf. c: 没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46833674/

相关文章:

c++ - 与 gdb 一起使用的 Makefile

c++ - 为什么行>列时数组的内存占用更大

c - 正确设置cmakelist来编译项目

c - 有时在 C 中修复段错误

c - 如何在 gdb 中打印 OpenMP 并行区域的局部变量?

在 gdb session 中调用 malloc 失败

c - EVP 读取 PEM 私钥无法正常工作

c++ - 为什么 nl_langinfo(CODESET) 与语言环境字符映射不同?

linux - PHP exec(myexe) 在 PHP 应用程序中失败,但在 CLI 中失败。在用户 "apache"下运行失败

c - 如何在 gdb 中使用输入文件