title: Alphabetic comparison without strcmp()?
body: <p>I am attempting to write a custom strcmp() function without using the built-in function.  So far, my code feels sort of convoluted.  Essentially I want the order of characters to be like this:</p>
  
  <ol>
  <li>Special characters (in the order they appear)</li>
  <li>Numbers</li>
  <li>Alphabetic characters, in order, but capitals first, i.e. "AaBbCcDd"</li>
  </ol>
  
  <p>It is to return 1 if string1 comes before string2, -1 if string2 comes before string1, and 0 if they are equal.</p>
  
  <p>Here is the code I have:</p>
  
  <pre><code>int strcmp(char * string1, char * string2)
  {
      while((*string1 != '\0') &amp;&amp; (*string2 != '\0') &amp;&amp; (*string1 == *string2))
      {
          ++string1;
          ++string2;
      }
  
      //If both are now zero, they are equal
      if (*string1 == *string2 == '\0') { return 0; }
  
      //If string1 is comes before, return 1
      //If string2 is comes before, return -1
      int type1 = (isalpha(string1) ? 2 : (isnum(string1) ? 1 : 0))
      int type2 = (isalpha(string2) ? 2 : (isnum(string2) ? 1 : 0))
      return ((type1 &lt; type2) 1 : ((type2 &lt; type1) -1 :
          (((*string1 &gt;= 'a') ? (*string1 - 'a')*2+1 : (*string1 - 'a')*2) &lt; 
          ((*string2 &gt;= 'a') ? (*string2 - 'a')*2+1 : (*string2 - 'a')*2) ? 1 : -1)));
  }
  </code></pre>
  
  <p>There are two things I am not sure about:</p>
  
  <ol>
  <li>Whether assigning "categories" is the right approach.  Right now I assign type 0 to special characters, type 1 to numbers, and type 2 to alphabetic characters.  This way I can quickly compare types.</li>
  <li>Whether my approach of using algebraic operations is appropriate for establishing the character order of alphabetic characters.</li>
  </ol>
  
  <p>Are these good approaches?  Are there better?  Please keep in mind I am maximizing for efficiency.</p>