+ 3
What strcmp function returns and why?
Function strcmp
3 Answers
+ 2
The strcmp function each characters ib the two are compared one by one . They are subtracted since C treats single characters as integers it is allowed. Hence 0 if all the characters in both the two strings are same and if not the difference value of first non identical character is produced. Note that the integer values of a character in a strings are their ASCII values.
+ 3
http://www.cplusplus.com/reference/cstring/strcmp/
The answer is under return value.
Why? Probably because the programmers decided it. :)
+ 1
strcmp is a string function returns an integer after comparing two strings
if the return value is 0 the two strings are equal
if the value is greater than zero the first string is greater
otherwise second string is greater
example
======
#include<string.h>
void main()
{
char ch[40],ch2[30];
clrscr();
printf(âEnter string1 :â);
gets(ch);
printf(âEnter string2 :â);
gets(ch2);
if(strcmp(ch,ch2)==0)
printf(âTwo strings are equalâ);
else if(strcmp(ch,ch2)>0)
printf(âFirst string is greaterâ);
else
printf(âSecond string is greaterâ);
getch();
}