Re: memcmp versus strstr; reaction to chr(0)

Discussion in 'C Programming' started by Thomas Matthews, Jul 24, 2003.

  1. Walter Dnes wrote:

    > When I asked in another thread about string comparisons, I forgot
    > about the chr(0) booby-trap in C strings. Since I want to compare
    > random binary data, this is important to me. Someone correct me if I'm
    > wrong; strstr stops at chr(0). memcmp doesn't treat chr(0) as a
    > delimiter, and can compare ranges (the word "strings" is incorrect here)
    > that included embedded chr(0). I realize that memcmp won't
    > automatically scan a larger string, but I can put it in a loop to sweep
    > through a larger string. Too bad that memmem is not standard.
    >


    The function memcmp() compares two regions of memory.
    The function strstr() searches a string for another (sub-)string.
    A string is a collection of chars terminated by a '\0'. If the
    string is not terminated correctly, undefined behavior occurs.

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
     
    Thomas Matthews, Jul 24, 2003
    #1
    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. crjunk
    Replies:
    2
    Views:
    16,914
    crjunk
    Aug 8, 2003
  2. Joona I Palaste

    Re: memcmp versus strstr; reaction to chr(0)

    Joona I Palaste, Jul 24, 2003, in forum: C Programming
    Replies:
    0
    Views:
    442
    Joona I Palaste
    Jul 24, 2003
  3. Burne C
    Replies:
    3
    Views:
    1,363
    Peter Ammon
    Jul 25, 2003
  4. Dan Pop
    Replies:
    0
    Views:
    391
    Dan Pop
    Jul 24, 2003
  5. Paul Butcher
    Replies:
    12
    Views:
    782
    Gary Wright
    Nov 28, 2007
Loading...

Share This Page