Guardian C Library Calls Reference Manual

Reference to Library Calls
Guardian TNS C Library Calls Reference Manual128833 3-65
fscanf
The conversion codes must agree in number and type with the pointers in obj_ptr....
Example
In this example, fscanf reads data from $a.b.c, converts it to a double value, and places it
in the variable x:
#include <stdioh>
FILE *fp;
int status;
double r;
double x;
fp = fopen("$a.b.c", "r");
/* ... */
status = fscanf(fp, "%f", &x);
r = sqrt(x);
printf("The square root of %f is %f", x, r);
%
matches a literal percent sign in the input; for example:
count=fscanf(fp, “Stock went up %d%% ”, &increase);
[
introduces a scan set, which is a list of expected characters. The scan set
consists of all characters between the left bracket [ and its matching right
bracket ], which is the end of the conversion code. If the character following
the left bracket is a circumflex (^), fscanf reads input until it encounters one of
the characters in the scan set. If the character following the left bracket is not a
circumflex, fscanf reads input until it encounters a character not in the scan
set. In either case, fscanf reads at most width characters. The corresponding
obj_ptr must be a pointer to char that points to the first character of an array
large enough to accommodate width+1 elements. fscanf stores the matching
input data, followed by a null character, in this array. To include a right
bracket in the scan set, make it the first character of the set, as in [ ]abc] or
[^]abc].