title: populating struct fields in a separate function in C
body: <p>getting empty values in the struct for this implementation since pointers are freed after call to myFunc ends. what's a good way of populating a struct when its fields are populated in a different function?</p>
  
  <pre><code>struct Poke {
      char *name;
      char *type;
  };
  
  void myFunc(struct Poke *p) {
  
      char fish[5] = "fish";
      char *name = fish;
      char fillet[8] = "fillet";
      char *type = fillet;
  
      p-&gt;name = name;
      p-&gt;type = type;
  
  }
  
  int main () {
  
      struct Poke p;
      myFunc(&amp;p);
  
      printf("%s\n", (&amp;p)-&gt;name);
      printf("%s\n", (&amp;p)-&gt;type);
  
  }
  </code></pre>