title: Reading a file with scanf and a do while loop
body: <p>I'm reading a file with <code>scanf</code>. Each line is just one data field, so I have a a do while loop. Basically what I do is, read the first information for build the root (i'm using this for build a BST). But when gets inside the do while. Reads weird things. Read and create correct all data, but for each iteration for the loop, call twice times the same method for read a file and I don't what is happening now.</p>
  
  <pre><code>comp_node_ptr read_competitor_node(int id, FILE * competitor_filename){
  
     int scan_status;
  
     int feet;
     double inches;
  
     competitor_node * tmp_node;
  
     tmp_node = calloc(1, sizeof(tmp_node));
  
     scan_status = fscanf(competitor_filename, "%[^\n]\n", tmp_node -&gt; name );
  
     if(scan_status == EOF){
        printf("End Of File. \n");
        free(tmp_node);
        return NULL;
     }
  
     tmp_node -&gt; id = id;
  
     fscanf(competitor_filename, "%[^\n]\n", tmp_node -&gt; addres );
  
     fscanf(competitor_filename, "%[^\n]\n", tmp_node -&gt; phone_number );
  
     fscanf(competitor_filename, "%d %lf", &amp;feet, &amp;inches );
     tmp_node -&gt; cucumber = convertToInches(feet, inches);
  
     fscanf(competitor_filename, "%d %lf", &amp;feet, &amp;inches );
     tmp_node -&gt;carrot = convertToInches(feet, inches);
  
     fscanf(competitor_filename, "%d %lf", &amp;feet, &amp;inches );
     tmp_node -&gt; bean = convertToInches(feet, inches);
  
     printNode(tmp_node);
  
     return tmp_node;
  
  }
  
  root = read_competitor_node(id, competitor_table_file);
  
  do{
     id++;
     tmp_node = read_competitor_node(id, competitor_table_file);
     add_competitor(root, tmp_node);
  }while(tmp_node != NULL);
  </code></pre>
  
  <p>And prints the following data:</p>
  
  <pre><code>Margaret Mouse     1 Southern 9565          1 ft -0.500000 in     2 ft -3.200001 in     1 ft -4.500000 in -134217728 ft 0.000000 in 
                 2                     1 ft -4.500000 in     1 ft -4.500000 in     1 ft -4.500000 in     0 ft 0.000000 in 
  Bert Hill      3 Central 2010          1 ft -7.200001 in     1 ft -8.200001 in     2 ft -11.700001 in 156587349 ft -4.000000 in 
                 4         �   27263573 ft -4.000000 in 27263573 ft -4.000000 in 27263573 ft -4.000000 in     0 ft 0.000000 in 
  Donald Duck     5 Marine 1234567          2 ft -0.400000 in     2 ft -4.500000 in     1 ft -6.200001 in 145402538 ft -8.000000 in 
                 6         �   27263570 ft -8.000000 in 27263570 ft -8.000000 in 27263570 ft -8.000000 in -67108864 ft 0.000000 in 
  End Of File. 
  </code></pre>
  
  <p>2, 4 and 6 I don't know where that come. 1, 3 and 5 is the correct data from the file that i'm reading, but all the other where they come?</p>
  
  <p>the struct data is the following:</p>
  
  <pre><code>typedef struct competitor_status {
  
  int id;
  char name[MAX_TEXT_LENGTH];
  char addres[MAX_TEXT_LENGTH];
  char phone_number[MAX_TEXT_LENGTH];
  float cucumber;
  float carrot;
  float bean;
  
  struct competitor_status * left; /* links to teams with more or same points */
  struct competitor_status * right; /* links to teams with less points */
  
  } competitor_node;
  
  typedef competitor_node * comp_node_ptr;
  </code></pre>