title: Allocating memory for a string in C using malloc
body: <p>I am trying to allocate memory for an array of strings using malloc. The size of each string is not known before the input from the user, so this is how I tried to allocate memory for each element in the array.</p>
  
  <p>I have some errors with the code, but can't figure them out or can't understand them. I am getting an error regarding the allocation. Can anyone tell me what's wrong about this? </p>
  
  <pre><code>bool read_strings(char * strings[], int n) 
  {
      int i = 0;
      while (i&lt;n)
      {
          char string[MAX_LENGTH];
          if (scanf("%s", string)!=1)
              return false;
          char* memory= (char*)malloc(sizeof(char)*strlen(string));
          if (memory == NULL)
              return false;
          memory = string;
          strings[i] = memory;
          i++;
      }
      return true;
  }
  </code></pre>
  
  <p>Thanks a lot!</p>