title: How can I save a string in a dynamic 2d array?
body: <p>This part of my code is about signup. </p>
  
  <p>I only can signup for one time, the next time the program stops. </p>
  
  <p>What is the problem?</p>
  
  <pre><code>while (1) { /*usercounter initialized with 0*/
      printf("enter your order:\n");
      gets(buffer);
      order = strtok(buffer, " ");
      if (strcmp(order, "signup") == 0) {
          usercounter++;
          if (usercounter &gt; 50) {
              username=realloc(username,usercounter*sizeof(*username));
              password=realloc(password, usercounter*sizeof(*password));
          }
          username[(usercounter - 1)] = (char *)malloc(50*sizeof(char));
          strcpy(username[usercounter - 1], strtok(NULL, " "));
          password[(usercounter - 1)] = (char *)malloc(50*sizeof(char));
          strcpy(password[usercounter - 1], strtok(NULL, "\n"));
          free(buffer);
          continue;
      }
  }
  </code></pre>