程序停止,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++编译这个程序,它与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: No such file or directory
只是gdb抱怨找不到scanf
的源代码。