strcoll - C string.h

C examples for string.h:strcoll

Type

function

From

<cstring> 

<string.h>

Description

Compare two strings using locale

Prototype

int strcoll ( const char * str1, const char * str2 );

Parameters

Parameter Description
str1 C string to be compared.
str2 C string to be compared.

Return Value

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

Demo Code

#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;
}

Related Tutorials