开发者

How to resolve the segmentation fault due to strtok()?

I am getting segmentation fault when the below line is executed:

result = strtok(data,delimiter);

I have given the backtrace :

Program received signal SIGSEGV开发者_C百科, Segmentation fault.
0x44359e85 in strtok () from /lib/libc.so.6
(gdb) backtrace
#0  0x44359e85 in strtok () from /lib/libc.so.6
#1  0x08048c02 in main () at multiply.c:36

How to resolve this?


There are few reasonable possibilities for the segmentation fault you have:

  • Passing NULL as data in the first call to strtok().
  • Passing NULL as delimiter.
  • Using a read-only string as data, which is forbidden, since strtok() modifies the source string.

I see you know how to use gdb, so put a break-point before the call to strtok() and see what values are passed to the function.

You can also use valgrind. It will help you to find the specific problem you have.

But, if you want better answers in stack-overflow, you must give some more code and other iformation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜