title: How can I correctly assign a new string value?
body: <p>I'm trying to understand how to solve this trivial problem in C, in the cleanest/safest way. Here's my example:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(int argc, char *argv[])
  {
      typedef struct
      {
          char name[20];
          char surname[20];
          int unsigned age;
      } person;
  
      // Here I can pass strings as values...how does it work?
      person p = {&quot;John&quot;, &quot;Doe&quot;, 30};
  
      printf(&quot;Name: %s; Age: %d\n&quot;, p.name, p.age);
  
      // This works as expected...
      p.age = 25;
  
      //...but the same approach doesn't work with a string
      p.name = &quot;Jane&quot;;
  
      printf(&quot;Name: %s; Age: %d\n&quot;, p.name, p.age);
  
      return 1;
  }
  </code></pre>
  <p>The compiler's error is:</p>
  <blockquote>
  <p>main.c: In function ‘main’: main.c:18:
  error: incompatible types when
  assigning to type ‘char[20]’ from type
  ‘char *’</p>
  </blockquote>
  <p>I understand that C (not C++) doesn't have a String type and instead uses arrays of <code>char</code>s, so another way to do this was to alter the example struct to hold pointers of <code>char</code>s:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(int argc, char *argv[])
  {
      typedef struct
      {
          char *name;
          char *surname;
          int unsigned age;
      } person;
  
      person p = {&quot;John&quot;, &quot;Doe&quot;, 30};
  
      printf(&quot;Name: %s; Age: %d\n&quot;, p.name, p.age);
  
      p.age = 25;
  
      p.name = &quot;Jane&quot;;
  
      printf(&quot;Name: %s; Age: %d\n&quot;, p.name, p.age);
  
      return 1;
  }
  </code></pre>
  <p>This works as expected, but I wonder if there a better way to do this.</p>