memcmp() and strcmp()

Discussion in 'C++' started by blueblueblue2005, Jul 3, 2005.

  1. hi, I am reading the description of memcmp and strcmp, it seems there
    is no big difference between these two functions. except that memcmp
    takes void pointer parameters. so why string.h has these two functions
    doing the same thing?
     
    blueblueblue2005, Jul 3, 2005
    #1
    1. Advertisements

  2. blueblueblue2005

    Stephen Howe Guest

    > hi, I am reading the description of memcmp and strcmp, it seems there
    > is no big difference between these two functions. except that memcmp
    > takes void pointer parameters. so why string.h has these two functions
    > doing the same thing?


    There is a big difference.
    strcmp() compares characters up until it sees the first '\0' in either
    string.
    As soon as character difference is found or '\0' is found it returns.

    memcmp() does not look for '\0'. It looks for the first difference
    considering the size specified.

    Stephen Howe
     
    Stephen Howe, Jul 3, 2005
    #2
    1. Advertisements

  3. blueblueblue2005

    SnaiL Guest

    By the way, not "string.h" but "cstring" header. And you need to know
    that it is C, but not C plus plus. std::basic_string<T> is used in C++.
     
    SnaiL, Jul 3, 2005
    #3
  4. yeah, this is another I am confused, I found a c++ website, under
    standard library, they include string.h as c standard library, also
    says that cstring is another name for string.h

    the website I am looking at is cplusplus.com
     
    blueblueblue2005, Jul 3, 2005
    #4
  5. blueblueblue2005

    Jack Klein Guest

    On 3 Jul 2005 12:37:42 -0700, "SnaiL" <> wrote in
    comp.lang.c++:

    > By the way, not "string.h" but "cstring" header. And you need to know
    > that it is C, but not C plus plus. std::basic_string<T> is used in C++.


    Both memcmp() and strcmp() are part of the standard C++ library and
    must be available on every conforming hosted C++ implementation.

    Both <string.h> and <cstring> are allowed as headers to prototype
    these two functions. <string.h> is deprecated, but unlikely to be
    actually removed in the real world.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Jul 4, 2005
    #5
    1. Advertisements

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. memcmp for <

    , Mar 23, 2005, in forum: C++
    Replies:
    16
    Views:
    1,200
    Jack Klein
    Mar 24, 2005
  2. Burne C
    Replies:
    3
    Views:
    1,550
    Peter Ammon
    Jul 25, 2003
  3. Sidney Cadot

    memcmp() semantics

    Sidney Cadot, Nov 23, 2003, in forum: C Programming
    Replies:
    6
    Views:
    820
    Arthur J. O'Dwyer
    Nov 25, 2003
  4. Preets
    Replies:
    4
    Views:
    719
  5. Replies:
    13
    Views:
    676
    Ben Pfaff
    Dec 23, 2006
  6. wolverine
    Replies:
    0
    Views:
    402
    wolverine
    Oct 28, 2006
  7. Martin

    Defeating Optimisation for memcmp()

    Martin, Nov 10, 2007, in forum: C Programming
    Replies:
    46
    Views:
    1,797
    Charlie Gordon
    Nov 23, 2007
  8. Replies:
    3
    Views:
    1,652
    James Kanze
    Mar 11, 2009
Loading...