p*s
2 楼
【 以下文字转载自 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
【 原文由 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
3 楼
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 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 【 以下文字转载自 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, ":");
In your case, it is the const string. Disaster will happen,
you're lucky that it happens soon enough.
【在 p******s 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 【 以下文字转载自 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
4 楼
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 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 【 以下文字转载自 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, ":");
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 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 【 以下文字转载自 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
5 楼
好奇怪哦,编译 Hello World 时,得到如下 warning:
line 10: warning: improper pointer/integer combination: arg #2
运行后得到Segmentation fault.
删掉 core 后重新编译,居然一切正常,连warning也没有.
【在 p******s 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 【 以下文字转载自 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, ":");
line 10: warning: improper pointer/integer combination: arg #2
运行后得到Segmentation fault.
删掉 core 后重新编译,居然一切正常,连warning也没有.
【在 p******s 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 【 以下文字转载自 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, ":");
相关阅读
不是ROOT可以在UNIX下装CXTERM吗?^M solution[转载] To those who want to use Yahoo freely...[转载] A simple question about perl傻傻的问a question about regular expressionRe: how to record the process end time in a child process and obtain i[转载] hostname 问题Any idea on batch renaming files?emacs中有什么键可以完成象vi中命令模式下的%的操作?Emergency : How to generate core file?Question about DDD DebuggerNeed urgent help on a samll shell script problem!请问在UNIX下cc编译出来的文件为什么不能执行?how to record the process end time in a child process and obtain it in the parent process?请教一个问题一个很丢人的问题求助Re: 这样的问题还能继续吗?Re: 不是ROOT可以在UNIX下装CXTERM吗?How to write a program that produces itself using PERL?