+ 3
What strcmp function returns and why?
Function strcmp
3 odpowiedzi
+ 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();
}