memcmp() and strcmp()

  • Thread starter blueblueblue2005
  • Start date
B

blueblueblue2005

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?
 
S

Stephen Howe

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
 
S

SnaiL

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

blueblueblue2005

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
 
J

Jack Klein

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.
 

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

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top