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

Discussion in 'C Programming' started by Joona I Palaste, Jul 24, 2003.

  1. Walter Dnes <> scribbled the following:
    > 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.


    Yes, that's more or less it. To memcmp, the byte value 0 (0x00) is just
    another byte value amongst others. It holds no special significance.
    BTW, chr(0) sounds like Pascal terminology. In C, a character and its
    numeric value are identical.

    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "As we all know, the hardware for the PC is great, but the software sucks."
    - Petro Tyschtschenko
    Joona I Palaste, 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,809
    crjunk
    Aug 8, 2003
  2. Thomas Matthews

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

    Thomas Matthews, Jul 24, 2003, in forum: C Programming
    Replies:
    0
    Views:
    505
    Thomas Matthews
    Jul 24, 2003
  3. Burne C
    Replies:
    3
    Views:
    1,312
    Peter Ammon
    Jul 25, 2003
  4. Dan Pop
    Replies:
    0
    Views:
    362
    Dan Pop
    Jul 24, 2003
  5. Paul Butcher
    Replies:
    12
    Views:
    677
    Gary Wright
    Nov 28, 2007
Loading...

Share This Page