File:  [MW Coherent from dump] / coherent / a / usr / man / ALL / fscanf
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



fscanf()                      STDIO                      fscanf()




Format input from a file stream

#include <stdio.h>
iinntt ffssccaannff(_f_p, _f_o_r_m_a_t, _a_r_g_1, ... _a_r_g_N)
FFIILLEE *_f_p; cchhaarr *_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 ffpprriinnttff  to write  some data  into a
file, and then reads it back using ffssccaannff.


#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



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.