由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - [转载] UNIX下的strtok
相关主题
Unix下好好的到了linux下segment faultsegmentation fault when using "script"
[转载] 活见鬼了---搞不定的程序UNIX文件系统一问
奇怪的 C 问题[转载] Help, about clock().
about strtok()owner of file
[转载] UNIX下的一个奇怪问题!who knows how to view the core file?
偶要疯了!fork() and execve() in Unix
问一个Unix Shell Script 的问题sed question??
lp service produce segmentation fault大侠帮忙看看这段程序,想不通
相关话题的讨论汇总
话题: strtok话题: str话题: unix话题: null话题: char
进入Unix版参与讨论
1 (共1页)
p******s
发帖数: 938
1
【 以下文字转载自 Programming 讨论区 】
【 原文由 phageous 所发表 】
要利用strtok来进行一些string的操作,结果却是segmentation fault,
code如下:
#include
#include
void main() {
char *str;
char *line="15:wildwood.eecs.umich.edu:018032:24.79 wildwood.eecs.umich.edu:018031:21.11 wildwood.eecs.umich.edu:018044:14.83 wildwood.eecs.umich.edu:018093:4.32";
str=strtok(line, ":");
printf("First token is %s\n", str);
while( (str=strtok(NULL, ":")) !=NULL)
printf("Next token is %s \n", str
c******r
发帖数: 512
2
Never use this function. It modifies the first arguments.
In your case, it is the const string. Disaster will happen,
you're lucky that it happens soon enough.

【在 p******s 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 phageous 所发表 】
: 要利用strtok来进行一些string的操作,结果却是segmentation fault,
: code如下:
: #include
: #include
: void main() {
: char *str;
: char *line="15:wildwood.eecs.umich.edu:018032:24.79 wildwood.eecs.umich.edu:018031:21.11 wildwood.eecs.umich.edu:018044:14.83 wildwood.eecs.umich.edu:018093:4.32";
: str=strtok(line, ":");

c****d
发帖数: 116
3
Please change the line:
char *line=.....
to
char line[1024]=....
to see what's the problem.

【 以下文字转载自 Programming 讨论区 】
【 原文由 phageous 所发表 】
要利用strtok来进行一些string的操作,结果却是segmentation fault,
code如下:
#include
#include
void main() {
char *str;
char *line="15:wildwood.eecs.umich.edu:018032:24.79 wildwood.eecs.umich.edu:018031:21.11 wildwood.eecs.umich.edu:018044:14.83 wildwood.eecs.umich.edu:018093:4.32";
str=strtok(line, ":");
printf("First token is %

【在 p******s 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 phageous 所发表 】
: 要利用strtok来进行一些string的操作,结果却是segmentation fault,
: code如下:
: #include
: #include
: void main() {
: char *str;
: char *line="15:wildwood.eecs.umich.edu:018032:24.79 wildwood.eecs.umich.edu:018031:21.11 wildwood.eecs.umich.edu:018044:14.83 wildwood.eecs.umich.edu:018093:4.32";
: str=strtok(line, ":");

c**t
发帖数: 2744
4
好奇怪哦,编译 Hello World 时,得到如下 warning:
line 10: warning: improper pointer/integer combination: arg #2
运行后得到Segmentation fault.
删掉 core 后重新编译,居然一切正常,连warning也没有.

【在 p******s 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 phageous 所发表 】
: 要利用strtok来进行一些string的操作,结果却是segmentation fault,
: code如下:
: #include
: #include
: void main() {
: char *str;
: char *line="15:wildwood.eecs.umich.edu:018032:24.79 wildwood.eecs.umich.edu:018031:21.11 wildwood.eecs.umich.edu:018044:14.83 wildwood.eecs.umich.edu:018093:4.32";
: str=strtok(line, ":");

1 (共1页)
进入Unix版参与讨论
相关主题
大侠帮忙看看这段程序,想不通[转载] UNIX下的一个奇怪问题!
Regular expression偶要疯了!
segmentation fault 求救问一个Unix Shell Script 的问题
[转载] 大侠救命哪!!!lp service produce segmentation fault
Unix下好好的到了linux下segment faultsegmentation fault when using "script"
[转载] 活见鬼了---搞不定的程序UNIX文件系统一问
奇怪的 C 问题[转载] Help, about clock().
about strtok()owner of file
相关话题的讨论汇总
话题: strtok话题: str话题: unix话题: null话题: char