strtok麻烦 [英] strtok trouble

查看:95
本文介绍了strtok麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对c很新,我正在尝试建立一个网络服务器。


好​​吧,这是我的问题。如果浏览器

发送请求文件的标题,我想反编译标题。


我正在考虑使用strtok为每个命令创建单个字符串,在

标题但我在尝试运行

程序时总是会出现分段错误。任何人都可以给我一个例子或什么?这是我用来调用标题分析函数的

代码...:

} else {

//传入数据

geturl(buf);

sendpage(i," /var/www/html/test.html");

disconnect(i,& master);

}


char geturl(char * header)

{

}


昨天我已经删除了我的strtok代码以尝试别的东西,因为它没有工作但是我希望b $ b不起作用有人可以帮我这个。


提前致谢,


Robert

解决方案
"罗伯特" < R **** @ hetnet.nl>。写道:

我对c很新,我正在尝试建立一个网络服务器。

好的,这是我的问题。如果浏览器发送请求文件的标题,我想反编译标题。

我正在考虑使用strtok为每个命令创建单个字符串,在标题中但是在尝试运行
程序时,我总是遇到分段错误。任何人都可以给我一个例子或什么?这是我用来调用标题分析函数的代码片段......:
}其他{
//传入数据
geturl(buf) ;
sendpage(i,/ var / www / html / test.html");
断开(i,& master);
}

char geturl(char * header)
{
}

昨天我已经删除了我的strtok代码以尝试别的东西,因为它没有工作但是我希望有人可以帮助我。




这样做,你删除了代码中唯一有趣的部分。

太可悲了。您想使用strtok()发布原始代码吗?


-

6 * 9 = 42(基数13)


> 6 * 9 = 42(基数13)


完全放在一边 - 我有类似的这一个给你;-)


你有没有知道圣诞节和万圣节是在同一天发生的吗?


12月25日= 10月31日



" Robert" < R **** @ hetnet.nl>。 schrieb im Newsbeitrag

新闻:bj ********** @ reader08.wxs.nl ...

我很擅长c和我正在尝试建立一个网络服务器。

好吧,这是我的问题。如果浏览器发送请求文件的标题,我想反编译标题。

我正在考虑使用strtok为每个命令创建单个字符串,在标题中但是在尝试运行
程序时,我总是遇到分段错误。任何人都可以给我一个例子或什么?这是我用来调用标题分析函数的代码片段......:
}其他{
//传入数据
geturl(buf) ;
sendpage(i,/ var / www / html / test.html");
断开(i,& master);
}

char geturl(char * header)
{


我的水晶球已经停止服务,所以我可以猜测:

1)标题点字符串文字

2)标题是一个NULL指针

3)strtok返回NULL(因为它找不到令牌)而你

取消引用这个NULL指针

}

我昨天删除了我的strtok代码尝试别的东西,因为它没有用,但我希望有人可以帮助我。


如果您希望我们找到问题,最好发布

失败代码:)
在此先感谢,

Robert




Robert也是如此:)


Hi, i am pretty new to c and i am trying to make a webserver.

Alright, here''s my problem. I want to decompile the header if a browser
sends a header requesting a file.

I was thinking of using strtok to make single strings of each command, in
the header but i always get segmentation faults when trying to run the
program. Can anyone send me an example or something? Here''s the piece of
code i use to call the function which does the header analyzing...:
} else {
// incoming data
geturl(buf);
sendpage(i, "/var/www/html/test.html");
disconnect(i, &master);
}

char geturl(char *header)
{
}

I''ve removed my strtok code yesterday to try something else because it
didn''t work but i hope someone can help me with this.

Thanks in advance,

Robert

解决方案

"Robert" <R.****@hetnet.nl> wrote:

Hi, i am pretty new to c and i am trying to make a webserver.

Alright, here''s my problem. I want to decompile the header if a browser
sends a header requesting a file.

I was thinking of using strtok to make single strings of each command, in
the header but i always get segmentation faults when trying to run the
program. Can anyone send me an example or something? Here''s the piece of
code i use to call the function which does the header analyzing...:
} else {
// incoming data
geturl(buf);
sendpage(i, "/var/www/html/test.html");
disconnect(i, &master);
}

char geturl(char *header)
{
}

I''ve removed my strtok code yesterday to try something else because it
didn''t work but i hope someone can help me with this.



And doing so, you removed the only interesting part of your code.
Too sad. Would you like to post the original code using strtok()?

--
6 * 9 = 42 (base 13)


> 6 * 9 = 42 (base 13)

Completely aside - I have a similar one of these for you ;-)

Did you know that christmas and halloween occur on the same day?

Dec 25 = Oct 31



"Robert" <R.****@hetnet.nl> schrieb im Newsbeitrag
news:bj**********@reader08.wxs.nl...

Hi, i am pretty new to c and i am trying to make a webserver.

Alright, here''s my problem. I want to decompile the header if a browser
sends a header requesting a file.

I was thinking of using strtok to make single strings of each command, in
the header but i always get segmentation faults when trying to run the
program. Can anyone send me an example or something? Here''s the piece of
code i use to call the function which does the header analyzing...:
} else {
// incoming data
geturl(buf);
sendpage(i, "/var/www/html/test.html");
disconnect(i, &master);
}

char geturl(char *header)
{
My crystal ball is out of service, so I can just guess:
1) header points to a string literal
2) header is a NULL pointer
3) strtok returns NULL (because it could not find the token) and you
dereference this NULL pointer
}

I''ve removed my strtok code yesterday to try something else because it
didn''t work but i hope someone can help me with this.
If you want us to find the problem, it would be a good idea to post the
failing code :)
Thanks in advance,

Robert



Robert as well :)


这篇关于strtok麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆