Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!cs.uoregon.edu!ns.uoregon.edu!milton!amigo From: amigo@milton.u.washington.edu (The Friend) Newsgroups: comp.lang.c Subject: Reading from file to array Keywords: files & arrays Message-ID: <1991Apr3.210510.11672@milton.u.washington.edu> Date: 3 Apr 91 21:05:10 GMT Organization: University of Washington Lines: 27 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 ---------------------------------------------------------------------