title: reading csv to struct
body: <p>I am trying to put textfile to the struct</p>
  
  <p>have issues with assigning values form text file to the struct, it keeps printing me the last value being printed incompletely.</p>
  
  <p>Can you kindly help me out with the issue?</p>
  
  <p>Thank you in advance.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #define MAX_LEN 422498
  #define MAX_KEY 128
      struct record
      {
          char* a;
          char* b;
      };
  
      int main(int argc, char **argv){
          char* input=argv[1];
          char* output=argv[2];
          char* buff[MAX_LEN];
  
  
          char *delimiter = ";";
  
  
          //printf("%s\n",input);
          //printf("%s\n",output);
  
          FILE *fp;
          fp = fopen(input, "r"); //opening file*/
  
          if( fp == NULL )
             {
                perror("Error while opening the file.\n");
                exit(EXIT_FAILURE);
             }
             int rowsNum=0;
             struct record* recArr = malloc(3 * sizeof (struct record));
             //struct record recArr[4];
          //recArr=malloc(1 * 2*sizeof(char*));
             /*recArr[0].a="aa";
             recArr[0].b="bb";
             recArr[1].a="cc";
             recArr[1].b="dd";
             recArr[2].a="ee";
             recArr[2].b="ff";
  
          printf("%s\n", recArr[0].a);
          printf("%s\n\n", recArr[0].b);
          printf("%s\n", recArr[1].a);
          printf("%s\n\n", recArr[1].b);
          printf("%s\n", recArr[2].a);
          printf("%s\n\n", recArr[2].b);*/
          while (fgets(buff, MAX_LEN, (FILE*)fp)!=NULL)
         {       
              //recArr=realloc(recArr, (rowsNum+1) * 2*sizeof(char*));
  
              //char* Key = strtok(buff, delimiter);
              //char* Value = strtok(NULL, delimiter);
  
              recArr[rowsNum].a=strtok(buff, delimiter);
              recArr[rowsNum].b=strtok(NULL, delimiter);
  
              printf("%s\n", recArr[rowsNum].a);
              printf("%s\n\n", recArr[rowsNum].b);
              /*Key=NULL;
              Value=NULL;*/
              rowsNum++;
              printf("%d\n", rowsNum);
          }
          fclose(fp);
  
          int i;
          for (i=0;i&lt;3;i++)
          {
              printf("%s\n",  recArr[i].a);
              printf("%s\n\n", recArr[i].b);
          }
          //printf("%d\n", rowsNum);
  
      }
  </code></pre>