C: strtok delivers segmentation fault

前端 未结 2 1821
挽巷
挽巷 2021-01-28 05:52

I am trying to read a file line by line, and tokenize each line, which have strings separated by spaces and tabs. However, when I run my program, I get the a Segmentation

2条回答
  •  渐次进展
    2021-01-28 06:41

    Looks like you are printing without checking for NULL for token pointer.

    If you need to print all tokens you also need to print inside while loop after strtok system call with addition to non-NULL check for token.

提交回复
热议问题