strtok program crashing

前端 未结 4 1963
旧时难觅i
旧时难觅i 2020-12-19 23:15

the program for strtok given on http://www.opengroup.org/onlinepubs/000095399/functions/strtok.html crashes everytime..

#include 
...
char *t         


        
4条回答
  •  自闭症患者
    2020-12-19 23:54

    char *line is a pointer and you are pointing it to a constant string ("LINE TO BE SEPARATED"). This fails when strtok attempts to modify that string. It would be better to qualify this variable as const char *line—still wouldn't work, but might lead to a helpful warning when you try to pass it to strtok.

    Meanwhile the array char line[] can be modified (it's not const) and is only initialised to contain the string.

提交回复
热议问题