title: Alphabetical comparison of two strings in C
body: <p>My programming experience is extremely scattered and I can't seem to find the answer to what I hope is a simple question. I had an assignment last week that I didn't properly finish and it's bugging me to death.</p>
  
  <p>I was supposed to compare two strings alphabetically without using strcmp and find out which string is alphabetically first via a function using pointers. </p>
  
  <pre><code>int strcmp373(char *str1, char *str2) {
    while(*str1 != '\0')
    {
      str1++;
    }
    while(*str2 != '\0')
    {
      str2++;
    }
  if(*str1 == *str2)
  
  }
  </code></pre>
  
  <p>This is my horrible attempt, my thought process being to use the null terminated value. I was hoping I could get some insight and explain how it works?</p>
  
  <p>Here's a copy of the assignment specifications for reference.</p>
  
  <p>Write a function called strcmp373, which compares two strings in precisely the same way that strcmp does in the C library . This time, please use "pointer syntax" in writing this function. That is, the [ ] operator should not be used at all when referring to particular characters in string1 and string2; instead, all parameters and local variables should be declared as pointers (using the * symbol). Please be sure that you emulate the strcmp C function. Note that strcmp returns 0 if the two strings are equal, even though 0 normally means false in C. The sign of other return values matters is used to indicate in what way the strings are not the same, but the precise return value is not important. 
  You may not use any of the built-in C string library functions to complete this code. </p>
  
  <p>Here is the prototype of this function: </p>
  
  <pre><code>int strcmp373(char *, char *);
  </code></pre>
  
  <p>And here is a main function which you can use to test strcmp373. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "hw3.h" // to be discussed
  
  int main() {
  char str1[81], str2[81];
  char again = 'y', newline;
  while (again == 'y') {
      printf("Enter a string\n");
      scanf("%s", str1);
      printf("Enter another string\n");
      scanf("%s", str2);
      int comp = strcmp373(str1, str2);
      if (comp &lt; 0)
          printf("%s is alphabetically before %s\n", str1, str2);
      else if (comp &gt; 0)
          printf("%s is alphabetically after %s\n", str1, str2);
      else printf("%s and %s are the same\n", str1, str2);
      printf("Again? (y/n)\n");
      scanf("%c%c", &amp;newline, &amp;again);
  }
  }
  </code></pre>