473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

strtok trouble

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
Nov 13 '05 #1
33 4427
"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)
Nov 13 '05 #2
> 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

Nov 13 '05 #3

"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 :)
Nov 13 '05 #4
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote:
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


Huh? Please, elaborate on this, I can't figure it out ...

--
6 * 9 = 42 (base 13)
Nov 13 '05 #5
Irrwahn Grausewitz <ir*****@freenet.de> wrote in
news:0c********************************@4ax.com:
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote:
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


Huh? Please, elaborate on this, I can't figure it out ...


Decimal 25 (e.g. 25d) is the same as Octal 31 (e.g. 031). Since December
and Decimal can be abbreviated as Dec and October and Octal can be
abbreviated as Oct you can then write the math equivalence as Dec 25 = Oct
31 which appears to look as though the two dates have some equivalence,
which the do not. This is your basic "play on words".

--
- Mark ->
--
Nov 13 '05 #6
Irrwahn Grausewitz <ir*****@freenet.de> wrote:
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote:
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


Huh? Please, elaborate on this, I can't figure it out ...


Read "Dec" and "Oct" as abbreviations for number bases.

- Kevin.

Nov 13 '05 #7
Allan Bruce wrote:
Did you know that christmas and halloween occur on the same day? Dec 25 = Oct 31


That is SO old...

--
Tom Zych
This email address will expire at some point to thwart spammers.
Permanent address: echo 'g******@cbobk.pbz' | rot13
Nov 13 '05 #8
"Mark A. Odell" <no****@embeddedfw.com> wrote:
Irrwahn Grausewitz <ir*****@freenet.de> wrote in
news:0c********************************@4ax.com :
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote:
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


Huh? Please, elaborate on this, I can't figure it out ...


Decimal 25 (e.g. 25d) is the same as Octal 31 (e.g. 031). Since December
and Decimal can be abbreviated as Dec and October and Octal can be
abbreviated as Oct you can then write the math equivalence as Dec 25 = Oct
31 which appears to look as though the two dates have some equivalence,
which the do not. This is your basic "play on words".

Maybe I wasn't able to figure this out, just because
my brain is just /too/ exalted. 8o)

<irreproducible hysterical laughter>

Irrwahn

--
I used to be schizophrenic, but we're all right now.
Nov 13 '05 #9
"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)
Nov 13 '05 #10
> 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

Nov 13 '05 #11
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote:
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


Huh? Please, elaborate on this, I can't figure it out ...

--
6 * 9 = 42 (base 13)
Nov 13 '05 #12
Irrwahn Grausewitz <ir*****@freenet.de> wrote in
news:0c********************************@4ax.com:
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote:
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


Huh? Please, elaborate on this, I can't figure it out ...


Decimal 25 (e.g. 25d) is the same as Octal 31 (e.g. 031). Since December
and Decimal can be abbreviated as Dec and October and Octal can be
abbreviated as Oct you can then write the math equivalence as Dec 25 = Oct
31 which appears to look as though the two dates have some equivalence,
which the do not. This is your basic "play on words".

--
- Mark ->
--
Nov 13 '05 #13
"Robert" <R.****@hetnet.nl> writes:
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)
{
}


In other words, you call a function that doesn't do anything.
Why you think this is interesting to us, I have no idea.

Post the code that's a problem. We can't help you if you post
the code that *isn't* a problem.
--
"C has its problems, but a language designed from scratch would have some too,
and we know C's problems."
--Bjarne Stroustrup
Nov 13 '05 #14
Irrwahn Grausewitz <ir*****@freenet.de> wrote:
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote:
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


Huh? Please, elaborate on this, I can't figure it out ...


Read "Dec" and "Oct" as abbreviations for number bases.

- Kevin.

Nov 13 '05 #15
Irrwahn Grausewitz <ir*****@freenet.de> wrote in
news:eb********************************@4ax.com:
Maybe I wasn't able to figure this out, just because
my brain is just /too/ exalted. 8o)


Do you mean exalted:

http://www.dict.org/bin/Dict?Form=Di...&Query=Exalted

or exhausted?

http://www.dict.org/bin/Dict?Form=Di...uery=Exhausted

:-)

--
- Mark ->
--
Nov 13 '05 #16
Allan Bruce wrote:
Did you know that christmas and halloween occur on the same day? Dec 25 = Oct 31


That is SO old...

--
Tom Zych
This email address will expire at some point to thwart spammers.
Permanent address: echo 'g******@cbobk.pbz' | rot13
Nov 13 '05 #17
"Mark A. Odell" <no****@embeddedfw.com> wrote:
Irrwahn Grausewitz <ir*****@freenet.de> wrote in
news:0c********************************@4ax.com :
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote:
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


Huh? Please, elaborate on this, I can't figure it out ...


Decimal 25 (e.g. 25d) is the same as Octal 31 (e.g. 031). Since December
and Decimal can be abbreviated as Dec and October and Octal can be
abbreviated as Oct you can then write the math equivalence as Dec 25 = Oct
31 which appears to look as though the two dates have some equivalence,
which the do not. This is your basic "play on words".

Maybe I wasn't able to figure this out, just because
my brain is just /too/ exalted. 8o)

<irreproducible hysterical laughter>

Irrwahn

--
I used to be schizophrenic, but we're all right now.
Nov 13 '05 #18
Robert wrote:
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...:
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.


I was having trouble with my car, the transmission was slipping when
going up hills. I took out the transmission and brought the rest of the
car to the mechanic. He laughed at me.
Please post a complete, compiliable, minimal program that demonstrates
your problem. There are many many things that can cause seg faults.


Brian Rodenborn
Nov 13 '05 #19
There is no strtok() in your code. Read man strtok carefully. Also keep in
mind that strtok is not reentrant (it uses a static pointer to your parsed
string), e.g. not usable if you are writing a multithreaded program.
Nov 13 '05 #20
"Mark A. Odell" <no****@embeddedfw.com> wrote:
Irrwahn Grausewitz <ir*****@freenet.de> wrote in
news:eb********************************@4ax.com :
Maybe I wasn't able to figure this out, just because
my brain is just /too/ exalted. 8o)


Do you mean exalted
or exhausted?


It is left as an exercise to the reader to find out.

8^)
--
6 * 9 = 42 (base 13)
Nov 13 '05 #21
"Robert" <R.****@hetnet.nl> writes:
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)
{
}


In other words, you call a function that doesn't do anything.
Why you think this is interesting to us, I have no idea.

Post the code that's a problem. We can't help you if you post
the code that *isn't* a problem.
--
"C has its problems, but a language designed from scratch would have some too,
and we know C's problems."
--Bjarne Stroustrup
Nov 13 '05 #22
Irrwahn Grausewitz <ir*****@freenet.de> wrote in
news:eb********************************@4ax.com:
Maybe I wasn't able to figure this out, just because
my brain is just /too/ exalted. 8o)


Do you mean exalted:

http://www.dict.org/bin/Dict?Form=Di...&Query=Exalted

or exhausted?

http://www.dict.org/bin/Dict?Form=Di...uery=Exhausted

:-)

--
- Mark ->
--
Nov 13 '05 #23
Robert wrote:
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...:
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.


I was having trouble with my car, the transmission was slipping when
going up hills. I took out the transmission and brought the rest of the
car to the mechanic. He laughed at me.
Please post a complete, compiliable, minimal program that demonstrates
your problem. There are many many things that can cause seg faults.


Brian Rodenborn
Nov 13 '05 #24
There is no strtok() in your code. Read man strtok carefully. Also keep in
mind that strtok is not reentrant (it uses a static pointer to your parsed
string), e.g. not usable if you are writing a multithreaded program.
Nov 13 '05 #25
"Mark A. Odell" <no****@embeddedfw.com> wrote:
Irrwahn Grausewitz <ir*****@freenet.de> wrote in
news:eb********************************@4ax.com :
Maybe I wasn't able to figure this out, just because
my brain is just /too/ exalted. 8o)


Do you mean exalted
or exhausted?


It is left as an exercise to the reader to find out.

8^)
--
6 * 9 = 42 (base 13)
Nov 13 '05 #26

It's a bit rough, for you gave us a very short description.

Anyway a good way to find out is to check out if the header pointer
isn't NULL, and do not forget that the 2nd call to strtok (if you desire
to continue to extract tokens from the same string) must be NULL!!!!!

Check out the man pages, and if you really want to learn strtok, get its
code. You'll see that it quite easy the get the hang of it.

I forgot to mention that when there isn't any more tokens, strtok
returns NULL.

Even then, if you continue to get the core dumped message, the only
solution to understand the error is throug gdb or any other debugger.

I had many problems with strtok, not because of any memory leacks or
anything similar to that. It was a problem with an internal pointer in
strtok's source. The solution was to use a class to control the tricky
pointer and compile the code with g++.

Well, that's it.
--
Posted via http://dbforums.com
Nov 13 '05 #27
netlinux <me*********@dbforums.com> writes:
I had many problems with strtok, not because of any memory leacks or
anything similar to that. It was a problem with an internal pointer in
strtok's source. The solution was to use a class to control the tricky
pointer and compile the code with g++.


There is no need to switch to C++. You can simply use a
different function instead of strtok(), one that cures the
many problems that strtok() has.
--
"I'm not here to convince idiots not to be stupid.
They won't listen anyway."
--Dann Corbit
Nov 13 '05 #28

It's a bit rough, for you gave us a very short description.

Anyway a good way to find out is to check out if the header pointer
isn't NULL, and do not forget that the 2nd call to strtok (if you desire
to continue to extract tokens from the same string) must be NULL!!!!!

Check out the man pages, and if you really want to learn strtok, get its
code. You'll see that it quite easy the get the hang of it.

I forgot to mention that when there isn't any more tokens, strtok
returns NULL.

Even then, if you continue to get the core dumped message, the only
solution to understand the error is throug gdb or any other debugger.

I had many problems with strtok, not because of any memory leacks or
anything similar to that. It was a problem with an internal pointer in
strtok's source. The solution was to use a class to control the tricky
pointer and compile the code with g++.

Well, that's it.
--
Posted via http://dbforums.com
Nov 13 '05 #29
netlinux <me*********@dbforums.com> writes:
I had many problems with strtok, not because of any memory leacks or
anything similar to that. It was a problem with an internal pointer in
strtok's source. The solution was to use a class to control the tricky
pointer and compile the code with g++.


There is no need to switch to C++. You can simply use a
different function instead of strtok(), one that cures the
many problems that strtok() has.
--
"I'm not here to convince idiots not to be stupid.
They won't listen anyway."
--Dann Corbit
Nov 13 '05 #30
Robert wrote:

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

Hi, I am taking General Science for two weeks now, and I
want to build a thermonuclear reactor...

--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+
Nov 13 '05 #31
In article <3F***************@ev1.net>,
Charles Richmond <ri******@ev1.net> wrote:
Robert wrote:

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

Hi, I am taking General Science for two weeks now, and I
want to build a thermonuclear reactor...


That's easy. Just keep booting windows. It's bound to happen.
Nov 13 '05 #32
can anybody tell me what exactly strtok function will do
Jul 19 '06 #33
can anybody tell me what exactly strtok function will do with example
Jul 19 '06 #34

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alex Vinokur | last post by:
Here is some program with using strtok() and std::string. Why does strtok() affect str2 in function func2()? ====== File foo.cpp : BEGIN ====== #include <cstring> #include <string> #include...
1
by: Robert | last post by:
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...
23
by: kbhat | last post by:
I had written some code using strtok_r for parsing strings with two "levels" of delimiters. The code was working like a charm, until it suddenly broke one day. You see, I was applying strtok on...
6
by: gyan | last post by:
Hi How strtok track through string? char *strtok(char *s1, const char *s2); As i know The first call (with pointer s1 specified) returns a pointer to the first character of the first...
13
by: ern | last post by:
I'm using strtok( ) to capture lines of input. After I call "splitCommand", I call strtok( ) again to get the next line. Strtok( ) returns NULL (but there is more in the file...). That didn't...
8
by: hu | last post by:
hi, everybody! I'm testing the fuction of strtok(). The environment is WinXP, VC++6.0. Program is simple, but mistake is confusing. First, the below code can get right outcome:"ello world, hello...
3
by: nomad5000 | last post by:
Hi everybody! I'm having trouble using strtok to fill a matrix with int nrs. from a file. the code that is not working is the following: #include <iostream> #include <fstream> #include...
3
by: semi_evil | last post by:
I downloaded a few PHP scripts from various sites, in part to use them as is, and partly to study and learn from them. One script is littered with strtok() occurrences. So I checked the manual...
11
by: magicman | last post by:
can anyone point me out to its implementation in C before I roll my own. thx
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.