title: Char array comparison in C
body: <p>I have following function to compare two char arrays in C:</p>
  
  <pre><code>short test(char buffer[], char word[], int length) {
      int i;
      for(i = 0; i &lt; length; i++) {
          if(buffer[i] != word[i]) {
              return 0;
          }
      }
      return 1;
  }
  </code></pre>
  
  <p>And somewhere in main:</p>
  
  <pre><code>char buffer[5]; //which is filled correctly later
  ...
  test(buffer, "WORD", 5);
  </code></pre>
  
  <p>It returns 0 <strong>immediately</strong> at i = 0. If I change function to this:</p>
  
  <pre><code>short test(char buffer[], int length) {
      int i;
      char word[5] = "WORD";
      for(i = 0; i &lt; length; i++) {
          if(buffer[i] != word[i]) {
              return 0;
          }
      }
      return 1;
  }
  </code></pre>
  
  <p>... it works like a charm. In the first version of function test debugger says that buffer and word arrays are type of char*. In the second version of function test it says that the buffer is type of char* and the test array is type of char[]. Function strcmp() does not work neither.</p>
  
  <p>What is actually wrong here? Program is made for PIC microcontroller, compiler is C18 and IDE is MPLAB.</p>