title: Reading CSV from text file in C
body: <p>I'm trying to read CSV from a text file in C. The text file format is</p>
  
  <pre><code>1,Bob,bob@gmail.com
  2,Daniel,daniel@gmail.com
  3,John,john@gmail.com
  </code></pre>
  
  <p>When I run the program, the number displays fine but the name and email are being displayed as garbage. Here is my program...</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct {
      int number;
      char* name;
      char* email;
  } Owner;
  
  Owner owners[100];
  
  int load(char* filename)
  {
      char buffer[200];
      char token[50];
      Owner* owner;
      int owners_size = 0;
      FILE* file = fopen(filename, "r");
  
      while(fgets(buffer, 200, file) != NULL)
      {
          owner = (Owner*)malloc(sizeof(Owner));
          owner-&gt;number = atoi(strtok(buffer, ","));
          owner-&gt;name = strtok(NULL, ",");
          owner-&gt;email = strtok(NULL, ",");
          owners[owners_size++] = *owner;
      }
  
      fclose(file);
      return owners_size;
  }
  
  int main()
  {
      int choise, owners_size, index;
      char* owners_filename = "owners2.txt";
  
      owners_size = load(owners_filename);
  
      if(owners_size)
      {
          printf("owners size: %d\n\n", owners_size);
  
          for(index = 0; index &lt; owners_size; index++)
              printf("%d, %s %s\n", owners[index].number, owners[index].name, owners[index].email);
      }
  }
  </code></pre>
  
  <p>Can anyone tell me what the reason is. I appreciate your help.</p>