title: Reading columns from a file into a struct
body: <p>I have an assignment to read from a file a table similar to:</p>
  
  <pre><code>    MERCURY VENUS   EARTH   MARS    JUPITER SATURN  URANUS  NEPTUNE PLUTO
  Mass(10^24kg)   0.33    4.87    5.97    0.642   1898    568 86.8    102 0.0146
  Diameter(km)    4879    12104   12756   6792    142984  120536  51118   49528   2370
  Density(kg/m^3) 5427    5243    5514    3933    1326    687 1271    1638    2095
  Gravity(m/s^2)  3.7 8.9 9.8 3.7 23.1    9   8.7 11  0.7
  Escape_Velocity(km/s)   4.3 10.4    11.2    5   59.5    35.5    21.3    23.5    1.3
  Rotation_Period(hours)  1407.6  -5832.5 23.9    24.6    9.9 10.7    -17.2   16.1    -153.3
  ...
  </code></pre>
  
  <p>where there are 20 categories of values (mass, diameter, density...)
  and 9 planets.</p>
  
  <p>I'm trying to read in the data into a <code>struct planet</code> with the 20 components (mass, diameter, density...) and it compiles but I can't print any of the structure components in the output (like <code>p[2].A</code>) so it doesn't look like I'm even reading in the data from the file (and I definitely saved it in the right place). Because I'm trying to read columns into the <code>struct</code>, it's a bit messy...</p>
  
  <pre><code>typedef struct {char A[30]; char B[10]; char C[10]; float D; char E[10]; char F[10]; char G[10]; char H[10]; char I[10]; char J[10]; char K[10]; char L[10]; char M[10]; char N[10]; char O[10]; char P[10]; char Q[10]; char R[10]; char S[10]; char T[4]; char U[4];}planet;
  
  int main(void) {
  FILE * fp;
  FILE * fs;
  int i=0, j=0;
  planet p[9];
  char label[20][30];
  char x[20][30];
  
  fp=fopen("planets.txt", "r");
  if (fp==NULL)printf("ERROR\n");
  
  for(j=0; j&lt;9; i++){                             //this for loop read the planet names
      fscanf(fp, "%s", p[i].A);
      }
  
  for(i=0; i&lt;20; i++){                            //this for loop counts the rows and reads the labels
      fscanf(fp, "%s", label[i]);                 //label[0] corresponds to .B values
      for(j=0; j&lt;9; j++){                         //this for loop reads values across the rows and assigns them to the labels
          fscanf(fp, "%s", x[j]);
          if (i==0)strcpy(p[j].B, x[j]);
          else if (i==1) strcpy(p[j].C, x[j]);
          else if (i==2){
              p[j].D=atof(x[j]);
          }
          else if (i==3) strcpy(p[j].E, x[j]);
          else if (i==4) strcpy(p[j].F, x[j]);
          else if (i==5) strcpy(p[j].G, x[j]);
          else if (i==6) strcpy(p[j].H, x[j]);
          else if (i==7) strcpy(p[j].I, x[j]);
          else if (i==8) strcpy(p[j].J, x[j]);
          else if (i==9) strcpy(p[j].K, x[j]);
          else if (i==10) strcpy(p[j].L, x[j]);
          else if (i==11) strcpy(p[j].M, x[j]);
          else if (i==12) strcpy(p[j].N, x[j]);
          else if (i==13) strcpy(p[j].O, x[j]);
          else if (i==14) strcpy(p[j].P, x[j]);
          else if (i==15) strcpy(p[j].Q, x[j]);
          else if (i==16) strcpy(p[j].R, x[j]);
          else if (i==17) strcpy(p[j].S, x[j]);
          else if (i==18) strcpy(p[j].T, x[j]);
          else if (i==19) strcpy(p[j].U, x[j]);
      }
      i++;
  }
  </code></pre>
  
  <p>...</p>
  
  <p>Can anyone see a problem with this method? </p>