title: Read text file, break each line into separate arrays and sort in C
body: <p>I am trying to write a program that reads a text file and breaks each line into separate arrays so they can be sorted by date and name. I am still having trouble getting the 'sort by date' function to work/display properly, which is why I haven't attempted the sort by name function yet.</p>
  
  <p>I seem to be able to scan in the date and name arrays fine, but I think I need to modify the way I scan in the last array 'dates' because I need to separate them with a space after a comma. Problem is that I am not sure how to scan them in as a string seeing as they would have spaces between them and some names have different numbers of states. (I removed the spaces between the states in the text file at this point, but the text file needs to have them back in probably?)</p>
  
  <p>My code so far...</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #define MAX 30
  
  void sortByDate( int year[], char *name[], char *states[], int count);
  void sortByName(int year[], char name[], char states[], int count);
  
  int main()
  {
       int year[MAX]; 
       int i, a;
       int count = 0;
       int choice;
       char *name[MAX],
            *states[MAX];
       char b[MAX], c[MAX];
  
       FILE *inp = fopen("hurricanes.txt","r");               /* defining file input    */
  
       for(i=0;i&lt;MAX;i++)
       {
           if( feof(inp) )
          {
              break;
          } 
          fscanf(inp, "%d", &amp;a);
          fscanf(inp, "%s", &amp;b);
          fscanf(inp, "%s", &amp;c);
          year[i]=a;
          strcpy(&amp;name[i],b);
          strcpy(&amp;states[i],c);
          ++count; 
  
          printf("%d %s %s\n", year[i], &amp;name[i], &amp;states[i]);
       }
  
       printf("Press 0 to sort by date or 1 to sort by name: ");
       scanf("%d", &amp;choice);  
       if (choice == 0)
       {
           sortByDate(year, name, states, count); 
       }
       else if ( choice == 1)
       {
            //sortByName(year, name, states, count); 
       }
  
       getch();
       return 0;
  }
  
  void sortByDate( int year[], char *name[], char *states[], int count )
  {
       int d = 0;
       int c = 0;
  
       int yearTmp;
       char nameTmp[MAX], statesTmp[MAX];
       int order[count];
       int tmp = 0;
  
       FILE *outp = fopen("report.txt","w");                 /* defining file output   */
  
       for (c = 0; c &lt; count; ++c)
       {
           order[c] = c; 
       } 
  
       for (c = 0 ; c &lt; ( count - 1 ); c++)
       {
            for (d = 0 ; d &lt; count - c - 1; d++)
            {
                 if (year[d] &gt; year[d+1])
                 {
                      yearTmp = year[d];
                      year[d] = year[d+1]; 
                      year[d+1] = yearTmp; 
  
                      tmp = order[d];
                      order[d] = order[d+1];
                      order[d+1] = tmp;   
                }
            }
       }
  
       for (c = 0; c &lt; count; ++c)
       {
            printf("%d %-10s %s\n",  year[c], &amp;name[order[c]], &amp;states[order[c]]); 
       } 
  }
  
  //void sortByName(int year[], char name[], char states[], int count)
  //{
  //} 
  </code></pre>
  
  <p>The hurricanes.txt file....(again, I have removed the spaces between states but I think they need to be put back in and scanned differently?)</p>
  
  <pre><code>1960 Donna FL,NC
  1969 Camille MS
  1972 Agnes FL
  1983 Alicia TX
  1989 Hugo SC,NC
  2005 Katrina FL,LA,MS
  2005 Rita TX,LA
  2005 Wilma FL
  2008 Ike TX
  2009 Ida MS
  2011 Irene NC,NJ,MA,VT
  2012 Isaac LA
  1992 Andrew FL,LA
  1995 Opal FL,AL
  1999 Floyd NC
  2003 Isabel NC,VA
  2004 Charley FL,SC,NC
  2004 Frances FL
  2004 Ivan AL
  2004 Jeanne FL
  </code></pre>
  
  <p>Ok, So I made some changes from the suggestions posted here and they worked out great!</p>