Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - fgetc() read a character from a file stream http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fgetc()             Read a character from a file stream
------------------------------------------------------------------------------
 Declaration
   fileio.hdr

 Syntax
   func int fgetc extern
   param file fStream

 Arguments
   fStream is the file stream to manipulate.

 Return
   The character read from the file, or -1 if the end of the file has been
   reached.

 Description
   The fgetc() function reads a single character byte, from a buffered file
   stream, opened in either binary or text mode.

 Example
   #define EXAMPLE_FILE
   #include example.hdr

   proc HexDump
   param const char cFile
   // Display hex dump of a file
   vardef
      file fBuf
      int  iByte
      uint n
   enddef
   n := 0
   if fopen( fBuf, cFile, F_READ, F_BINARY )      // open file
      iByte := fgetc( fBuf )                      // get first byte
      do while iByte != -1                        // check for end of file
         ?? right( dechex( iByte ), 2 ) + " "     // display hex value
         n++
         if n > 20                                // new line
            n := 0
            ?
         endif
         iByte := fgetc( fBuf )                   // read another byte
      enddo                                       // close file
      fclose( fBuf )
   endif
   endproc
   
   proc Test_fgetc
   if exist( argv( 1 ) )
      HexDump( argv( 1 ) )
   else
      ? "Specify a file name"
   endif
   endproc

   proc main
   Test_fgetc()
   endproc

See Also: fgetln() fputc()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson