title: Strncmp implementation
body: <p>I have the following implementation of strncmp function with a test driver, however  that does`t compile.</p>
  
  <p>I`m also not sure if the logic is correct. Here is the error message from my compiler:</p>
  
  <blockquote>
    <p>warning: control may reach end of non-void function
          [-Wreturn-type]</p>
  </blockquote>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #undef strncmp
  
  int strncmp(const char *s, const char *t, size_t num)
  {
      for ( ; num &gt;0;  s++, t++, num--)
          if (*s == 0)
              return 0;
  
      if (*s == *t) {
          ++s;
          ++t;
      }
      else if (*s != *t)
          return *s - *t;  
  }
  
   int main ()
   {
     char str[][5] = { "R2D2" , "C3PO" , "R2A6" };
     int n;
     puts ("Looking for R2 astromech droids...");
     for (n=0 ; n&lt;3 ; n++)
       if (strncmp (str[n],"R2xx",2) == 0)
       {
         printf ("found %s\n",str[n]);
       }
     return 0;
   }
  </code></pre>