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);
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.