Siebel eScript Language Reference > Siebel eScript Commands > File I/O Methods in eScript >

Clib.fscanf() Method

This function reads data from a specified file and stores the data items in a series of parameters.


Clib.fscanf(filePointer, formatString, var1, var2, ..., varn)



A file pointer as returned by Clib.fopen()


A string containing formatting instructions for each data item to be read

var1, var2, ..., varn

Variables holding the values to be formatted


The number of input items assigned. This number may be fewer than the number of parameters requested if there was a matching failure. If there is an input failure (before the conversion occurs), this function returns EOF.


This function reads input from the file indicated by filePointer and stores that input in the var1, var2, ..., varn parameters following the formatString value according to the character combinations in the format string, which indicate how the file data is to be read and stored. The file must be open, with read access.

Characters from input are matched against the formatting instruction characters of formatString until a percent character (%) is reached. The % character indicates that a value is to be read and stored to subsequent parameters following formatString. Each subsequent parameter after formatString gets the next parsed value taken from the next parameter in the list following formatString.

A parameter specification takes this form:


For values for these items, see Formatting Input in eScript.


The following example shows uses of Clib.fscanf() with various options on the parameters.

var int1;
var int2;
var hour;
var min;
var sec;
var str;

var file = Clib.fopen("c:\\temp\\fscanf.txt", "r");
TheApplication().TraceOn("c:\\temp\\testoutput.txt", "allocation", "all");

// Simple scanf:
// input line e.g.: "Monday 10:18:00"
Clib.fscanf(file, "%s %i:%i:%i\n", str, hour, min, sec);
TheApplication().Trace(str + ", " + hour + ", " + min + ", " + sec);

// Using width specifier:
// input line e.g.: "1234567890"
Clib.fscanf(file, "%5i%5i\n", int1, int2);
TheApplication().Trace(int1 + ", " + int2);

// Reading hexadecimal integers and suppressing assignment to a variable:
// input line e.g.: "AB3F 456A 7B44"
Clib.fscanf(file, "%x %*x %x\n", int1, int2);
TheApplication().Trace(int1 + ", " + int2);

// Using character ranges:
// input line e.g.: "helloHELLO"
Clib.fscanf(file, "%[a-z]\n", str);


The script produces the following trace output:

COMMENT,"Monday, 10, 18, 0"
COMMENT,"12345, 67890"
COMMENT,"43839, 31556"

See Also

Clib.sinh() Method
Clib.sscanf() Method

Siebel eScript Language Reference