Concept Framework 2.0 documentation Contents | Index

standard.C.io.fgetc

Name Version Deprecated
fgetc version 1.0 no

Prototype:
string fgetc(number fd)

Parameters:
fd      [in] A valid file descriptor

Description:
fgetc reads a single character from the current position of a file associated with fd. The function then increments the associated file pointer (if defined) to point to the next character. If the stream is at end of file, the end-of-file indicator for the stream is set.


Example:
import standard.C.io

define FILENAME     "test.txt"

class Main {
     function Main() {
          var fd; 
          var ch = "";
          var buffer = "";          

          // Open file for read 
          if (fd = fopen(FILENAME, "r")) {               
               // Read in the characters and place them in "buffer"
               ch = fgetc(fd);
               while (!feof(fd)) {
                    buffer+= ch;
                    ch = fgetc(fd);
               }

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

Results 
Line one.
Line two.  

Returns:
fgetc returns the character read.

Documented by Simona Plesuvu, generation time: Fri Jan 21 18:06:19 2011 GMT(c)2011 RadGs Software