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 - <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
 char       *format-string;              Format-control string


    fscanf() reads data from the current position of 'stream' into the
    locations given by 'arguments'. 'format-string' determines how the
    input fields are to be interpreted.  Each argument must be a pointer
    to a variable with a type that corresponds to a type specifier in
    'format-string'.  'format-string' 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 that were successfully converted and
                assigned. A return value of EOF means an attempt was made
                to read at end-of-file. A return value of 0 means no
                fields were assigned.

  -------------------------------- 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