Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>fscanf() read formatted data from screen</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fscanf()                Read Formatted Data from Screen

 #include   <stdio.h>

 int        fscanf(stream,format-string[,argument...]);
 FILE       *stream;                     Pointer to FILE structure
 const char *format-string;              Format-control string


    fscanf() takes data from the current position of 'stream' and reads
    it into the locations given by 'argument', each of which must be a
    variable whose type corresponds to a type specifier in 'format-
    string'.  'format-string' governs the interpretation of the input
    fields.  It is identical to that used by the scanf() function; see
    scanf() for a complete description of 'format-string' and arguments.

    Returns:    The number of fields successfully converted and assigned;
                0 if no fields were assigned; and EOF if an attempt was
                made to read at end-of-file.

   -------------------------------- Example ---------------------------------

    This example opens a new file, places data in it, uses fscanf() to
    retrieve data from the stream, prints the data out, and closes the
    file.

           #include <stdio.h>

           FILE *stream;
           int num;
           char name[15];

           main()
           {
               if ((stream = fopen("scantest","w+")) != NULL) {
                  fputs("001Smith,J 002Jones,B",stream);
                  rewind(stream);
                  do
                      {
                      fscanf(stream,"%3d%15s",&num,name);
                      printf("found: %s (%d).\n",name,num);
                  } while (!feof(stream));
                fclose(stream);
                }
           }



See Also: scanf() cscanf() sscanf()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson