contents   index   previous   next



Clib.fscanf()

syntax:

Clib.fscanf(filePointer, formatString[, variables ...])

where:

filePointer - pointer to file to use.

 

formatString - string that specifies the final format.

 

variables - values to be converted to and formatted as a string.

 

return:

number - input items assigned on success, else EOF.

 

description:

This flexible function reads input from the file indicated by filePointer and stores in parameters following formatString according 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. It returns 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.

 

See Clib.scanf() for a description of this format string. The parameters following the format string will be set to data according to the specifications of the format string.

 

see:

Clib.scanf()

 

example:

// Given the following text file, weight.dat:

//  Crow, Barney      180

//  Claus, Santa      306 

//  Mouse, Mickey     2 

// the following code:

 

var fp = Clib.fopen("weight.dat", "r"); 

var FormatString = "%[,] %*c %s %d\n"; 

while (3 == Clib.fscanf(fp, FormatString,

       LastName, Firstame, weight))

   Clib.printf("%s %s weighs %d pounds.\n",

               FirstName, LastName, weight);

Clib.fclose(fp); 

 

// results in the following output:

//  Barney Crow weighs 180 pounds. 

//  Santa Claus weighs 306 pounds. 

//  Mickey Mouse weighs 2 pounds.

 


Clib.fseek()