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

Clib.fprintf() Method

This function writes a formatted string to a specified file.


Clib.fprintf(filePointer, formatString)



A file pointer as returned by Clib.fopen()


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


This method writes a formatted string to the file indicated by filePointer. For information on format strings used with Clib.fprintf(), see Table 33.


The following example shows uses of Clib.fprintf() with various format string parameters.

function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
   if (MethodName == "fprintfsamples")
      var intgr = 123456789;
      var flt = 12345.6789;
      var hour = 1;
      var min = 7;
      var sec = 0;
      var str = "Hello World";
      var file = Clib.fopen("c:\\temp\\fprintf.txt", "w");

      // Simple formatting:
      Clib.fprintf(file, "(1) %s, it is now %i:%i:%i pm.\n", str, hour, min, sec);
      Clib.fprintf(file, "(2) The number %i is the same as %x.\n", intgr, intgr);
      Clib.fprintf(file, "(3) The result is %f.\n", flt);

      // Flag values:
      // "+" forces a + or - sign; "#" modifies the type flag "x"

      // to prepend "0x" to the output. (Compare with the simple
      // formatting example.)
      Clib.fprintf(file, "(4) The number %+i is the same as %#x.\n", intgr, intgr);

      // Width values:
      // Note that the width is a minimal width, thus longer values
      // are not truncated.
      // "2" fills with spaces, "02" fills with zeros.
      var myWidth = 2;
      Clib.fprintf(file, "(5) %5s, it is now %2i:%02i:%02i pm.\n", str, hour, min,       sec);

      // Precision values:
      // ".2" restricts to 2 decimals after the decimal separator.
      // Note that the number will be rounded appropriately.
      Clib.fprintf(file, "(6) The result is %.2f.\n", flt);

      // A combined example:
      // <space> displays either space or minus;
      // "+" displays either plus or minus;
      // "020" uses a minimal width of 20, padded with zeros;
      // ".2" displays 2 digits after the decimal separator;
      // "*" uses the next argument in the list to specify the width.
      Clib.fprintf(file, "(7) The values are:\n%+020.2f\n% 020.2f\n% *.2f", flt,       intgr, 20, intgr);


      return (CancelOperation);
   return (ContinueOperation);

The script produces the following output:

(1) Hello World, it is now 1:7:0 pm.
(2) The number 123456789 is the same as 75bcd15.
(3) The result is 12345.678900.
(4) The number +123456789 is the same as 0x75bcd15.
(5) Hello World, it is now 1:07:00 pm.
(6) The result is 12345.68.
(7) The values are:

See Also

Clib.rsprintf() Method
Clib.sprintf() Method

Siebel eScript Language Reference