Connecting Tech Pros Worldwide Help | Site Map

memcmp() and strcmp()

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 05:49 AM
blueblueblue2005
Guest
 
Posts: n/a
Default memcmp() and strcmp()

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?


  #2  
Old July 23rd, 2005, 05:49 AM
Stephen Howe
Guest
 
Posts: n/a
Default Re: memcmp() and strcmp()

> hi, I am reading the description of memcmp and strcmp, it seems there[color=blue]
> 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?[/color]

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


  #3  
Old July 23rd, 2005, 05:49 AM
SnaiL
Guest
 
Posts: n/a
Default Re: memcmp() and strcmp()

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

  #4  
Old July 23rd, 2005, 05:49 AM
blueblueblue2005
Guest
 
Posts: n/a
Default Re: memcmp() and strcmp()

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

  #5  
Old July 23rd, 2005, 05:49 AM
Jack Klein
Guest
 
Posts: n/a
Default Re: memcmp() and strcmp()

On 3 Jul 2005 12:37:42 -0700, "SnaiL" <snail@btobits.com> wrote in
comp.lang.c++:
[color=blue]
> 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++.[/color]

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/~a...FAQ-acllc.html
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.