strtok trouble

R

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
 
R

Robert Stankowic

Robert said:
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 :)
 
I

Irrwahn Grausewitz

Robert said:
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()?
 
A

Allan Bruce

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
 
I

Irrwahn Grausewitz

Allan Bruce said:
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 ...
 
M

Mark A. Odell

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".
 
K

Kevin Easton

Irrwahn Grausewitz said:
Huh? Please, elaborate on this, I can't figure it out ...

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

- Kevin.
 
I

Irrwahn Grausewitz

Mark A. Odell said:
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
 
B

Ben Pfaff

Robert said:
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.
 
D

Default User

Robert said:
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
 
I

Isaac Mushinsky

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.
 
N

netlinux

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.
 
B

Ben Pfaff

netlinux said:
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.
 
C

Charles Richmond

Robert said:
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...
 
J

Jalapeno

Charles Richmond said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

strtok() 13
strtok 7
strtok problem 16
strtok exception handling 7
Segmentation fault when using strtok 4
strtok question 6
cannot read after \n using strtok() 10
strtok causes Segmentation fault 17

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top