Concept Framework 2.2 documentation Contents | Index

standard.C.io.fputc

Name Version Deprecated
fputc version 1.0 no

Prototype:
string fputc(string ch, number fd)

Parameters:
ch      [in] Character to be written
fd      [in] A valid file descriptor

Description:
fputc writes the single character ch to a file at the position indicated by the associated file position indicator (if defined) and advances the indicator as appropriate; the file is associated with fd. If the file cannot support positioning requests or was opened in append mode, the character is appended to the end of the stream.

Example:
import standard.C.io

define FILENAME "test.txt"

class Main {
     function Main() {
          var fd; 
          var ch;
          var i;
          var buffer = "Test of fputc\n"; 

          // Open file for write 
          if (fd = fopen(FILENAME, "w")) { 
               // Print line to stream using fputc
               ch = buffer[0];
               i = 0;
               while (ch) {
                    fputc(ch, fd);
                    i++;
                    ch = buffer[i];
               }

               freopen(FILENAME, "r", fd);
               buffer = "";
               fread(buffer, 1, 15, fd);

               echo "$buffer\n";
               fclose(fd);
          } else
               echo "Problem opening the file\n"; 
     }
}  

Results 
Test of fputc  

Returns:
fputc returns the written character.

Documented by Simona Plesuvu, generation time: Sun Jan 27 18:15:16 2013 GMT(c)2013 Devronium Applications