

fscanf()                      STDIO                      fscanf()




Format input from a file stream

#include <stdio.h>
iinntt ffssccaannff(_f_p, _f_o_r_m_a_t, _a_r_g_1, ... _a_r_g_N)
FFIILLEE *_f_p; cchhaarr *_f_o_r_m_a_t;
[_d_a_t_a _t_y_p_e] *_a_r_g_1, ... *_a_r_g_N;

fscanf  reads the  file stream  pointed  to by  fp, and  uses the
string format to format  the arguments arg1 through argN, each of
which must point to a variable of the appropriate data type.

fscanf returns either the  number of arguments matched, or EOF if
no arguments matched.

For more information on fscanf's conversion codes, see scanf.

***** Example *****

The  following example  uses ffpprriinnttff  to write  some data  into a
file, and then reads it back using ffssccaannff.


#include <stdio.h>

main ()
{
        FILE *fp;
        char let[4];



        /* open file into write/read mode */
        if ((fp = fopen("tmpfile", "wr")) == NULL) {
                printf("Cannot open 'tmpfile'\n");
                exit(1);
        }



        /* write a string of chars into file */
        fprintf(fp, "1234");



        /* move file pointer back to beginning of file */
        rewind(fp);



        /* read and print data from file */
        fscanf(fp, "%c %c %c %c",
                &let[0], &let[1], &let[2], &let[3]);
        printf("%c %c %c %c\n",
                let[3], let[2], let[1], let[0]);


COHERENT Lexicon                                           Page 1




fscanf()                      STDIO                      fscanf()



}


***** See Also *****

scanf(), sscanf(), STDIO

***** Notes *****

Because C does not perform type checking, it is essential that an
argument match  its specification.   For that reason,   fscanf is
best used  only to process data  that you are certain  are in the
correct  data format,  such as data  previously written  out with
fprintf.











































COHERENT Lexicon                                           Page 2


