Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!uwm.edu!ogicse!milton!amigo From: amigo@milton.u.washington.edu (The Friend) Newsgroups: comp.lang.c Subject: Re: reading from a file.sorting Keywords: files/sorting Message-ID: <1991Apr3.100911.29842@milton.u.washington.edu> Date: 3 Apr 91 10:09:11 GMT References: <1991Apr3.090427.25624@milton.u.washington.edu> Organization: University of Washington Lines: 36 amigo@milton.u.washington.edu (The Friend) writes: > I'm looking for a simple program that'll read ten words from a >string that has only got spaces between the words. I >had one example that had pointers - data read in via fscanf, >then the pointer was copied to another pointer array (each array >held one word). After the 10 words were read, the array was simply >incremented backwards in a for loop to print out correctly. >I have [REVISED]: > FILE *fp; > static char *data_array[11]; > int i; > main(){ > fp=fopen("test","r"); > for(i=0;i<10;i++){ > fscanf(fp,"%s", data_array[i]); > printf("%d %s",i,data_array[i]); /* test to see anything's put in data_array[] */ > } I'm missing something. I thought fscanf treats spaces as a _DELIM_ and therefore each word should be put into data_array[]. Basically all that I'm missing to complete this is what to do about fscanf not reading any words in. Thanks.. Scott -- --------------------------------------------------------------------- amigo@milton.u.washington.edu ---------------------------------------------------------------------