title: Strcat throws segmentation fault on simple getch-like password input
body: <p>I am using Linux and there is a custom function of which returns an ASCII <code>int</code> of current key sort of like <code>getch()</code>. When trying to get used to it and how to store the password I came into an issue, my code is as follows:</p>
  
  <pre><code>int main() {
      int c;
      char pass[20] = "";
  
      printf("Enter password: ");
      while(c != (int)'\n') {
          c = mygetch();
          strcat(pass, (char)c);
          printf("*");
      }
  
      printf("\nPass: %s\n", pass);
  
      return 0;
  }
  </code></pre>
  
  <p>Unfortunately I get the warning from GCC:</p>
  
  <pre><code>pass.c:26: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast
  /usr/include/string.h:136: note: expected ‘const char * __restrict__’ but argument is of type ‘char’
  </code></pre>
  
  <p>I tried using pointers instead of a char array for pass, but the second I type a letter it segfaults. The function works on its own but not in the loop, atleast not like getch() would on a Windows system.</p>
  
  <p>What can you see is wrong with my example? I am enjoying learning this.</p>
  
  <p><strong>EDIT:</strong> Thanks to the answers I came up with the following silly code:</p>
  
  <pre><code>int c;
  int i = 0;
  char pass[PASS_SIZE] = "";
  
  printf("Enter password: ");
  while(c != LINEFEED &amp;&amp; strlen(pass) != (PASS_SIZE - 1)) {
      c = mygetch();
      if(c == BACKSPACE) {
          //ensure cannot backspace past prompt
          if(i != 0) {
              //simulate backspace by replacing with space
              printf("\b \b");
              //get rid of last character
              pass[i-1] = 0; i--;
          }
      } else {
          //passed a character
          pass[i] = (char)c; i++;
          printf("*");
      }
  }
  pass[i] = '\0';
  printf("\nPass: %s\n", pass);
  </code></pre>