-2
print("ABCDEF , ABC : " . strcmp("ABCDEF" , "ABC"));
print("ABC , ABCDEF : " . strcmp("ABC" , "ABCDEF"));

output:

ABCDEF , ABC : 3 
ABC , ABCDEF : -3 

strcmp("ABCDEF" , "ABC") : 
A-A = 65-65 = 0, 
B-B = 66-66 = 0, 
C-C = 67-67 = 0,
D-A = 68-65 = 3, 

Then it stop at A when A-D is not 0.

ASCII value:

A = 65 
B = 66 
C = 67 
D = 68 
E = 69 
F = 70 

Is it correct how I understand strcmp()? , I just learned about this functions from internet.

Rizier123
  • 58,877
  • 16
  • 101
  • 156
Kugan Kumar
  • 423
  • 1
  • 8
  • 14
  • 1
    You definitely missed the formatting help page: http://stackoverflow.com/help/formatting – Rizier123 Jul 30 '15 at 17:27
  • Is it correct after strcmp("ABC" , "ABCDEF") compare C-C = 0, it return back to A(in string1) then subtract with D(of string2) ; A-D = 65-68 = -3 ? – Kugan Kumar Jul 30 '15 at 17:32
  • related: http://stackoverflow.com/q/9289571/3933332 – Rizier123 Jul 30 '15 at 17:32
  • im sorry first time im posting HTML code. thank you for pointing me the format. – Kugan Kumar Jul 30 '15 at 17:34
  • Rizier123 : i already read that link before posting my question, im not clear ;Is it correct after strcmp("ABC" , "ABCDEF") compare C-C = 0, it return back to A(in string1) then subtract with D(of string2) ; A-D = 65-68 = -3 so return -3 ? – Kugan Kumar Jul 30 '15 at 17:39

1 Answers1

0
if(strcmp("Taco", "Taco") == 0) {
 //This would return true. If the two words did not match, it would return false.
}

if(strcmp("Taco", "Taco") != 0) {
 //This would return false. If the two words did not match, it would return true.
}
GrumpyCrouton
  • 8,486
  • 7
  • 32
  • 71