title: fscanf dynamic array in C?
body: <p>So, my big homework is to make a who wants to be millionare game in C, but I have a little problem. I have a csv file with 5000 rows of datas like these:</p>
  
  <p>...</p>
  
  <p>4;How old I am?;22;dog;yellow;who knows;A;PERSONAL</p>
  
  <p>2;Where is Utrecht?;England;Nietherland;France;Sweden;B;GEOLOGY</p>
  
  <p>15;...</p>
  
  <p>...</p>
  
  <p>I always have to scan one question of the 5000, always needs to be more difficulty then the previous (easy, we have 15 levels of difficulties and 15 question), and needs to be printed on the screen (so I need the question, the answers and the others separately (GEOLOGY not needed)). But the problem: I have to use malloc always! How could be possible to know how long the string will be?</p>
  
  <p>I'm here:</p>
  
  <pre><code>    srand(time(NULL));
      int num=1;
      char* onerow=(char*) malloc(num*sizeof(char));
      int row=rand()%1000;
      char c;
  
      FILE *fp;
      fp = fopen("proba.txt", "r");
  
      for (int i=0; i&lt;=row-1; i++) {
          if(i!=row-1) {          //not the row we need, jump over it
              while(c!='\n')
                  c=fgetc(fp);
          }
          if(i==row-1) {
              for(int j=0; onerow[j]!='\n'; j++) {    //this is what we need
                  onerow[j]=fgetc(fp);
                  onerow = (char *) realloc(onerow, ++num*sizeof(char));
              }
          }
      }
      onerow[num]='\0';
      fclose(fp);
      printf("%s\n", onerow);
      free(onerow);
  }
  </code></pre>