title: Char * function in C
body: <p>I am currently trying to use a random string generator to produce a string. It looks like this:</p>
  
  <pre><code>char *randstring(int length) {
  
      static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#'?!";        
      char *randomString = NULL;
      int n = 0;
      if (length) {
          randomString = malloc(sizeof(char) * (length +1));
  
          if (randomString) {            
              for (n = 0;n &lt; length;n++) {            
                  int key = rand() % (int)(sizeof(charset) -1);
                  randomString[n] = charset[key];
              }
  
              randomString[length] = '\0';
          }
      }
      return randomString;
  }
  </code></pre>
  
  <p>I am trying to call it like this:</p>
  
  <pre><code>srand(time(NULL));
  int r = rand()%1000;
  char *string[1000];
  &amp;string = randomstring(r);
  </code></pre>
  
  <p>But when I do this, I get the following error:</p>
  
  <pre><code>error: invalid lvalue in assignment. 
  </code></pre>
  
  <p>I have looked online but I can not figure out why this is not working. Any suggestions? It has to do with the pointer, I assume.</p>