Connecting Tech Pros Worldwide Forums | Help | Site Map

diff between memcmp and strcmp

Newbie
 
Join Date: Aug 2006
Posts: 1
#1: Aug 4 '06
can anybody tell me what is difference between memcmp and strcmp

which one is better
efficient
and when to use memcmp or strcmp

Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,182
#2: Aug 4 '06

re: diff between memcmp and strcmp


They both compare char for char, however memcmp takes the number of characters to compare, strcmp assumes the pointers passed to it are pointers to strings which zero terminators.

Generally use strcmp when comparing strings, this makes it clear what you are doing, use memcmp when you are comparing anything other than strings.

I would imagine that there was not much difference in efficiency but I might be wrong.
Reply


Similar C / C++ bytes