In the example provided here, the strings are of different. I just wanted to ask what happens when at some index the array elements differ as in
char * str1 = "Hello";
char * str2 = "Helio";
j = strcmp(str1, str2);
"Will strcmp return the difference of ASCII's of the differing characters?" To save you the effort I've looked it up in the manual for you: http://www.keil.com/support/man/docs/c51/c51_strcmp.asp
hi, Stefan, I think that Affan means what does the "string1 is less than string2" means? Less in length? Less in what? Thanks, Oleg
"Less in length? Less in what?" Less lexicographically. Here's the source from a well known C library implementation:
int strcmp(char * src, char * dest) { int ret = 0 ; while(!(ret=*(unsigned char *)src- *(unsigned char *)dest) && *dest) { ++src; ++dest; } if(ret<0) ret = -1 ; else if(ret>0) ret=1; return(ret); }
Thanks, That was exactly what I was asking. I wanted to use the return values of strcmp for sorting strings.