whats wrong with this?

The Friend amigo at milton.u.washington.edu
Thu Apr 4 16:33:41 AEST 1991


Follow-up To: sender

     I have a program that >should< read characters from a file, since
the file contains 10 words with spaces to seperate them, I've got a while
loop looking for that. The for-loop does the job of updating the array
to the next level, and since we know there's 10 words, it should work a-ok.
Here's what we have:

          FILE *fp;
          char data, data_array[11][11];
          int i,j;

          if((fp=fopen("test.dat","r"))==NULL){
               printf("\n\nOoops..some error..\n\n");
               exit(0);
               }
          for(i=0;i<10;i++){
               while((data=getc(fp))!=' '){
                    data_array[i][j]=data;
                    j++;
               }
               j=0;
          }

     Where's the problem with this? Can someone recommend a better solution
to reading it in and putting it into arrays?

     Any help's appreciated - please mail it to me.. 

                                                  Thanks.
                                                 
-- 

     --------------------------------------------------------------------- 
     Scott Rowin                   /--/  amigo at milton.u.washington.edu
                                __////



More information about the Comp.lang.c mailing list