Fgets errors seg fault

前端 未结 1 994
长发绾君心
长发绾君心 2021-01-28 10:47

Is there any reason that a program, which compiled earlier, should seg fault at a point because of fgets? I changed no code related to it AT ALL. Suddenly I believe it is failin

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 11:03

    OK, the reason it use to "work" is you were clobbering an unimportant memory location. Changing your code shifted things around and now you are clobbering something important.

    You're passing an uninitialized pointer to createarray(). You wanted to do something like:

    int* aryHold;
    //...
    ... createarray(&aryHold ... 
    

    BTW, many compilers have the ability to catch this kind of error for you. If you haven't already, you might want to see if your compiler has an error checking option that could have saved you hassling with this (and perhaps find some other code that only "works" accidentally).

    0 讨论(0)
提交回复
热议问题