[comp.lang.c] Reading from file to array

amigo@milton.u.washington.edu (The Friend) (04/04/91)

     I need a way to read from a file to an array - data in the file
is a few words (10) with only spaces between them.

     The following is what I came up with:

     for(i=0;i<10;++i){
          while((data=fgetc(fp)) !=' '){
               data_array[j][i]=data;
               j++;
          }
               j=0;
          }

     Which I thought would read a character at a time into DATA, put
that into data_array[][] (incremented each round), and loop until space
is encountered. At the space the array drops down one, the array starts
at 0 again, and does it again. Problem I'm having is a lack of data even
comming in. I have fp=fopen("test.data","r"); so that shouldn't be a problem.

     I tried getc(fp) as well..

-- 

     --------------------------------------------------------------------- 
                         amigo@milton.u.washington.edu
     ---------------------------------------------------------------------