strtok trouble

Discussion in 'C Programming' started by Robert, Sep 5, 2003.

  1. Robert

    Robert Guest

    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, Sep 5, 2003
    #1
    1. Advertising

  2. "Robert" <> schrieb im Newsbeitrag
    news:bj9dm2$snh$...
    > 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 :)
    Robert Stankowic, Sep 5, 2003
    #2
    1. Advertising

  3. "Robert" <> 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)
    Irrwahn Grausewitz, Sep 5, 2003
    #3
  4. Robert

    Allan Bruce Guest

    > 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
    Allan Bruce, Sep 5, 2003
    #4
  5. Re: [OT] strtok trouble

    "Allan Bruce" <> 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)
    Irrwahn Grausewitz, Sep 5, 2003
    #5
  6. Re: [OT] strtok trouble

    Irrwahn Grausewitz <> wrote in
    news::

    > "Allan Bruce" <> 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 ->
    --
    Mark A. Odell, Sep 5, 2003
    #6
  7. Robert

    Kevin Easton Guest

    Re: [OT] strtok trouble

    Irrwahn Grausewitz <> wrote:
    > "Allan Bruce" <> 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.
    Kevin Easton, Sep 5, 2003
    #7
  8. Robert

    Tom Zych Guest

    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 '' | rot13
    Tom Zych, Sep 5, 2003
    #8
  9. Re: [OT] strtok trouble

    "Mark A. Odell" <> wrote:

    >Irrwahn Grausewitz <> wrote in
    >news::
    >
    >> "Allan Bruce" <> 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.
    Irrwahn Grausewitz, Sep 5, 2003
    #9
  10. Robert

    Ben Pfaff Guest

    "Robert" <> 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
    Ben Pfaff, Sep 5, 2003
    #10
  11. Mark A. Odell, Sep 5, 2003
    #11
  12. Robert

    Default User Guest

    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
    Default User, Sep 5, 2003
    #12
  13. 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.
    Isaac Mushinsky, Sep 5, 2003
    #13
  14. Re: [OT] strtok trouble

    "Mark A. Odell" <> wrote:

    >Irrwahn Grausewitz <> wrote in
    >news::
    >
    >> 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)
    Irrwahn Grausewitz, Sep 5, 2003
    #14
  15. Robert

    netlinux Guest

    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
    netlinux, Sep 6, 2003
    #15
  16. Robert

    Ben Pfaff Guest

    netlinux <> 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
    Ben Pfaff, Sep 6, 2003
    #16
  17. 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 |
    +----------------------------------------------------------------+
    Charles Richmond, Sep 6, 2003
    #17
  18. Robert

    Jalapeno Guest

    In article <>,
    Charles Richmond <> 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.
    Jalapeno, Sep 6, 2003
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adam Balgach
    Replies:
    2
    Views:
    555
    news-east
    Nov 28, 2004
  2. Alex Vinokur

    strtok() and std::string

    Alex Vinokur, Apr 14, 2005, in forum: C++
    Replies:
    6
    Views:
    4,891
    Pete Becker
    Apr 14, 2005
  3. strtok problem

    , Aug 28, 2003, in forum: C Programming
    Replies:
    4
    Views:
    495
  4. Fatih Gey

    segfault on strtok

    Fatih Gey, Oct 23, 2003, in forum: C Programming
    Replies:
    40
    Views:
    1,434
    nobody
    Nov 1, 2003
  5. Ram Laxman

    How can I use strtok for tokenize integers

    Ram Laxman, Apr 11, 2004, in forum: C Programming
    Replies:
    6
    Views:
    1,302
    Christopher Benson-Manica
    Apr 12, 2004
Loading...

Share This Page