title: Malloc a string array - C
body: <p>I have been trying to understand malloc and strings, can someone help me with this please - I get a bad pointer error </p>
  
  <pre><code>char password[100];
  char *key[2];   
  int textlen, keylen, i, j, k, t, s = 0;
  
  printf("password:\n") ;   
  scanf("%s",password);
  
  keylen = strlen(password) + 1;
  
  for(i=0; i &lt; keylen; i++)
  {                
      key[i] = (char*)malloc(keylen * sizeof(char));
      strcpy(key[i], password);
  }
  
  printf("The key is:\n\t %s", key);
  </code></pre>