[comp.lang.c] whats wrong with this?

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

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@milton.u.washington.edu
                                __////

avery@netcom.COM (Avery Colter) (04/08/91)

It would help to know what exactly is going wrong.


-- 
  ^     ^ 	Avery Ray Colter    
 /^\___/^\    	avery@netcom.com		{apple|claris}!netcom!avery  
(  o _ o  )   	elfcat@btr.btr.com		{decwrl|mips|sgi}!btr!elfcat
 \  /v\  /      71067.606@compuserve.com	(415) 839-4567
  \_*-*_/
    `-'			Afternoon has gently passed me by.	    - The
  ELFCAT! 		And Evening spreads itself against the sky.   Police