Function equivalent to strcmp()
You can skip the check for the end of one of the strings. If the other string ends before the one that you check the length for, the comparison of the characters will catch the difference:

int compare(char *str1, char *str2) {
  while (*str1 &amp;&amp; *str1 == *str2) {
    str1++;
    str2++;
  }
  return *str1 - *str2;
}


You can write the same using a for statement if you want it shorter (and less readable):

int compare(char *str1, char *str2) {
  for (;*str1 &amp;&amp; *str1 == *str2; str2++) str1++;
  return *str1 - *str2;
}


Just for the sake of it, you can make is shorter (mis)using recursion, but that is a rather terrible solution:

int compare(char *str1, char *str2) {
  return (*str1 &amp;&amp; *str1 == *str2) ? compare(++str1, ++str2) : *str1 - *str2;
}