Log in

View Full Version : Compare strings


just_doit
May 30, 2008, 12:30 PM
How can I compare two strings without using strcmp() function?

retsoksirhc
May 30, 2008, 12:35 PM
Not sure if it's exactly the same, but since PHP is based off C++, this might help.

In PHP, you can compare string with the == and === operators. == means same value, and === means same value and type.

theraos
Jun 15, 2008, 11:47 PM
Is this a trick question?

Do a strlen on each string make sure they are the same len and then do a memcmp

Or write your own strcmp function!

What is the purpose of this question - homework or an interview?

webi
Sep 24, 2008, 09:43 AM
Frist of all, strcmp is a C function, not c++.
You can find the answer with example in compare [C++ Reference] (http://www.cppreference.com/wiki/string/compare)