Reading from file to array

The Friend amigo at milton.u.washington.edu
Thu Apr 4 07:05:10 AEST 1991


     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 at milton.u.washington.edu
     ---------------------------------------------------------------------



More information about the Comp.lang.c mailing list