简体   繁体   English

C程序中的段错误

[英]Seg Fault Error in C Program

I had a program over 300 lines that worked 100% except for an fclose that caused a seg fault... Now, I can't even get my program to run at all. 我有一个超过300行的程序,除了会导致段错误的fclose以外,它们的工作率都达到了100%...现在,我什至无法使我的程序完全运行。 gdb gave me this error, which I honestly don't know how to interpret gdb给了我这个错误,老实说我不知道​​该怎么解释

    ____strtol_l_internal (nptr=0x0, endptr=0x0, base=10,
       group=<value optimized out>, loc=0x349c78d580) at ../stdlib/strtol_l.c:298
       298       while (ISSPACE (*s))

Can anyone tell me what this means? 谁能告诉我这是什么意思?

 readLinesFromFile(FILE* fPtr, int* num1, int* num2, char** strs, int lines)
 {
  int i;

  char data[50];

for (i = 0; i < lines; i++){
    fgets(data, 50, fPtr);
    strcpy (*(strs + i), strtok(data, " "));
    *(num1 + i) = atoi(strtok(NULL, " "));
    *(num2 + i) = atoi(strtok(NULL, " "));
}

Are you sure the SIGSEGV is triggered when you call an fclose ? 您确定在调用fclose时触发了SIGSEGV吗?

It looks like you're simple passing a NULL pointer as first parameted of strtol function (in some other part of the code) 看起来您很简单地将NULL指针作为strtol函数的第一个参数传递(在代码的其他部分)

Another option could be a stack totally messed up. 另一个选择是将堆栈完全弄乱。

Try to run it with gdb and when it crash use the command where to see the stack 尝试使用gdb运行它,当它崩溃时,使用命令where查看堆栈

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM