Siebel eScript Language Reference > C Language Library Reference > Clib File Input and Output Methods >

Clib Scan and Convert File Method


The Clib Scan and Convert File method reads data from a file and stores data items that exist in this file in a series of arguments. It returns one of the following values:

  • If successful, then it returns the number of input items it converted and stored.
  • If an input failure occurs before the conversion, then it returns the following value:

    EOF

Format

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

Table 146 describes the arguments for the Clib Scan and Convert File method.

Table 146. Arguments for the Clib Scan and Convert File Method
Argument
Description

filePointer

A file pointer that the Clib Open File method returns.

formatString

A string that contains format instructions that the Clib Open File method uses to read each data item in the file.

var1, var2, ..., varn

Variables that the Clib Open File method uses to store the values that it formats.

Usage

This method does the following work:

  1. Reads input from the file that the filePointer argument identifies.
  2. Matches characters that exist in the file with characters that the formatString argument specifies until it reaches a percentage symbol (%).

    The percentage symbol causes this method to read and store the values in the arguments that occur after the string that the formatString argument identifies.

  3. Parses each match that occurs after the value of the formatString argument.

    As it parses each match, it stores the result in a variable argument, such as var1, var2, ..., and varn. If a matching failure occurs, then the number of matches it parses might be fewer than the number of variable arguments you specify.

An argument specification uses the following format:

%[*][width]type

For values for these items, see Format Characters for Methods That Scan.

You must make sure that the file it reads is open and includes read access.

Example

The following example uses the Clib Scan and Convert File method with various options on the arguments:

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);
TheApplication().Trace(str);

Clib.fclose(file);

This example produces the following output:

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

Siebel eScript Language Reference Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices.