reading from a file.sorting

The Friend amigo at milton.u.washington.edu
Wed Apr 3 20:09:11 AEST 1991


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



More information about the Comp.lang.c mailing list