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 - fgetln() read a line of text from a text file http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fgetln()            Read a line of text from a text file
------------------------------------------------------------------------------
 Declaration
   fileio.hdr

 Syntax
   func logical fgetln extern
   param file fStream, ;
         char cLine

 Arguments
   fStream is the file stream to manipulate.
   cLine is the buffer receiving the text line.

 Return
   A logical indicating the success of operation.

 Description
   The fgetln() function reads a line of text from the file associated to
   fStream file and places the line in cLine. A carriage-return and/or
   line-feed character terminates the read. If fStream is at end of file, an
   empty string is returned.

   The cLine variable must be big enough to receive the input text, as
   fgetln() does not verify the size of the destination.

   The fStream must have been opened in F_READ mode.

 Example
   #define EXAMPLE_FILE
   #include example.hdr

   vardef static
      char( 20 ) cConfigOld := "\config.sys"
      char( 20 ) cConfigNew := "config.tmp"
   enddef
   
   func logical RemoveDriver
   param const char cDriver
   // Remove a driver from the config.sys file
   vardef
      file    fIn
      file    fOut
      char    cLine
      char    cSearch
      logical lChanged
   enddef
   lChanged := .f.
   cSearch := lower( cDriver )
   if fopen( fIn, cConfigOld, F_READ, F_TEXT )       // open input file
      if fopen( fOut, cConfigNew, F_CREATE, F_TEXT ) // open output file
         do while .not. feof( fIn )
            fgetln( fIn, cLine )     // read a line from input file
            if "device=" $ lower( cLine ) .and. cSearch $ lower( cLine )
               lChanged := .t.       // if search string found
               loop                  // do not copy line to output file
            endif
            fwriteln( fOut, cLine )  // write to output file
         enddo
         fclose( fOut )
      endif
      fclose( fIn )
   endif
   
   #ifndef EXAMPLE_FILE
   erase cConfigOld                  // exchange files
   rename cConfigNew to cConfigOld
   #endif
   
   return( lChanged )
   endfunc
   
   proc Test_fgetln
   if RemoveDriver( "himem.sys" )
      ? "Driver removed"
   else
      ? "Driver not found"
   endif
   endproc

   proc main
   Test_fgetln()
   endproc

See Also: fgetc() fputln()

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