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);
               }
          }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster