title: Passing strings to a struct in C
body: <p>I'm trying to do something simple in C that is passing 2 names (from argv[]) to a structure.
  I feel like I'm all over the place with this.
  This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct
  {
      char *name1;
      char *name2;
  
  }names;
  
  void writeNames(names* c ,char n1[], char n2[]){
      char* buff;
  
      buff = malloc(strlen(n1)*sizeof(char)+1);
      strcpy(buff, n1);
      c-&gt;name1 = buff;
      free(buff);
      buff = NULL;
  
      buff = malloc(strlen(n2)*sizeof(char)+1);
      strcpy(buff, n2);
      c-&gt;name2 = buff;
      free(buff);
      buff = NULL;
  }
  
  int main(int argc, char const *argv[])
  {
      names card;
      writeNames(&amp;card,argv[1],argv[2]);
      printf("%s %s\n",card.name1,card.name2);
      return 0;
  }
  </code></pre>
  
  <p>and this is what I get:</p>
  
  <pre><code>naming.c: In function ‘main’:
  naming.c:31:2: warning: passing argument 2 of ‘writeNames’ discards ‘const’ qualifier from pointer target type [enabled by default]
    writeNames(&amp;card,argv[1],argv[2]);
    ^
  naming.c:12:6: note: expected ‘char *’ but argument is of type ‘const char *’
   void writeNames(names* c ,char n1[], char n2[]){
        ^
  naming.c:31:2: warning: passing argument 3 of ‘writeNames’ discards ‘const’ qualifier from pointer target type [enabled by default]
    writeNames(&amp;card,argv[1],argv[2]);
    ^
  naming.c:12:6: note: expected ‘char *’ but argument is of type ‘const char *’
   void writeNames(names* c ,char n1[], char n2[]){
        ^
  </code></pre>
  
  <p>I don't really undertand what is going on. </p>