title: lexicographically sort in C
body: <p>I don't understand how works this sort.Why is it so? And how we compare characters in C , how can I understand which of them less or greater than other? 
  It's from book.</p>
  
  <p><em>Call the function compareStrings
  and have it return the value –1 if the first string is lexicographically less than the secondstring, 0 if the two strings are equal, and 1 if the first string is lexicographically greater
  than the second string. So, the function call</em></p>
  
  <pre><code>compareStrings ("alpha", "altered")
  </code></pre>
  
  <p><em>returns the value –1 because the first string is lexicographically less than the second
  string (think of this to mean that the first string occurs before the second string in a dictionary).And,
  the function call</em></p>
  
  <pre><code>compareStrings ("zioty", "yucca");
  </code></pre>
  
  <p><em>returns the value 1 because “zioty” is lexicographically greater than “yucca.”</em></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  
  struct entry
  {
      char word[15];
      char definition[50];
  };
  
  bool equalStrings(char s1[], char s2[])
  {
      bool areEqual = false;
      int i = 0;
  
      while(s1[i] != '\0' &amp;&amp; s2[i] != '\0' &amp;&amp; s1[i] == s2[i])
          i++;
  
      if(s1[i] == '\0' &amp;&amp; s2[i] == '\0')
          areEqual = true;
      else
          areEqual = false;
  
      return areEqual;
  }
  
  int lookup (struct entry dictionary[], char search[],int entries)
  {
      int low = 0;
      int high = entries - 1;
      int mid, result;
  
      while (low &lt;= high)
      {
          mid = (low + high) / 2;
          result = compareStrings (dictionary[mid].word, search);
  
          if(result == -1)
              low = mid + 1;
          else if(result == 1)
              high = mid - 1;
          else 
              return mid;
      }
  
      return -1;
  }
  
  int compareStrings(char s1[], char s2[])
  {
      int i = 0, answer;
  
      while(s1[i] == s2[i] &amp;&amp; s1[i] != '\0' &amp;&amp; s2[i] != '\0')
          i++;
  
      if(s1[i] &lt; s2[i])
          answer = -1;
      else if(s1[i] == s2[i])
          answer = 0;
      else 
          answer = 1;
  
      return answer;
  }
  
  int main()
  {
      struct entry dictionary[100] = 
      {
          {"aardvark", "a burrowing African mammal" },
          {"acumen", " a bottomless pit  "},
          {"addle", "to become confused "},
          {"agar", "a jelly made from seaweed" }
          {"affix", "to append; attach"}
      };
  
      char word[15];
      int entries = 10;
      int entry;
  
      printf("Enter word: ");
      scanf("%14s", word);
      entry = lookup (dictionary, word, entries);
  
      if(entry != -1)
          printf("%s\n", dictionary[entry].definition);
      else
          printf("Sorry, the word %s is not in my dictionary.\n", word);
  
      return 0;
  
  }
  </code></pre>
  
  <p>How understand that one greater than another? Thanks.</p>