C examples for string.h:strcoll
function
<cstring> <string.h>
Compare two strings using locale
int strcoll ( const char * str1, const char * str2 );
Parameter | Description |
---|---|
str1 | C string to be compared. |
str2 | C string to be compared. |
Returns an integral value indicating the relationship between the strings:
return value | indicates |
---|---|
<0 | the first character has a lower value in ptr1 than in ptr2 |
0 | the contents of both strings are equal |
>0 | the first character has a greater value in ptr1 than in ptr2 |
#include <stdio.h> #include <string.h> int main ()/*www .ja va 2 s . c o m*/ { char key[] = "apple"; char buffer[80]; do { printf ("Guess my favorite fruit(hint:apple)? "); fflush (stdout); scanf ("%79s",buffer); } while (strcoll (key,buffer) != 0); puts ("Correct answer!"); return 0; }