title: How does strcmp() work?
body: <p>I've been looking around a fair bit for an answer. I'm going to make a series of my own string functions like <code>my_strcmp()</code>, <code>my_strcat()</code>, etc.</p>
  
  <p>Does <code>strcmp()</code> work through each index of two arrays of characters and if the ASCII value is smaller at an identical index of two strings, that string is there alphabetically greater and therefore a 0 or 1 or 2 is returned? I guess what Im asking is, does it use the ASCII values of characters to return these results?</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>[REVISED]</p>
  
  <p>OK, so I have come up with this... it works for all cases except when the second string is greater than the first.</p>
  
  <p>Any tips? </p>
  
  <pre><code>int my_strcmp(char s1[], char s2[])
  {   
      int i = 0;
      while ( s1[i] != '\0' )
      {
          if( s2[i] == '\0' ) { return 1; }
          else if( s1[i] &lt; s2[i] ) { return -1; }
          else if( s1[i] &gt; s2[i] ) { return 1; }
          i++;
      }   
      return 0;
  }
  
  
  int main (int argc, char *argv[])
  {
      int result = my_strcmp(argv[1], argv[2]);
  
      printf("Value: %d \n", result);
  
      return 0;
  
  }
  </code></pre>