Skip to content

fread_charFreadCharFreadCharfread_charT_fread_char๐Ÿ”—

Short description๐Ÿ”—

fread_charFreadCharFreadCharfread_charT_fread_char โ€” Read one character from a text file.

Signature๐Ÿ”—

fread_char( file FileHandle, out string Char )void FreadChar( const HTuple& FileHandle, HTuple* Char )static void HOperatorSet.FreadChar( HTuple fileHandle, out HTuple charVal )def fread_char( file_handle: HHandle ) -> str

Herror T_fread_char( const Htuple FileHandle, Htuple* Char )

HString HFile::FreadChar( ) const

string HFile.FreadChar( )

Description๐Ÿ”—

The operator fread_charFreadChar reads a character from the input file defined by FileHandlefileHandlefile_handle. The input file must have been opened with open_fileOpenFile in text format.

The read character or the control character sequence โ€˜eofโ€™ is returned in parameter CharcharValchar. The operator fread_charFreadChar respects the encoding of the characters, unless the file was opened with the option 'ignore_encoding'"ignore_encoding" (see open_fileOpenFile). Thus, when opened with the correct encoding the operator fread_charFreadChar returns multi-byte characters at once. If necessary, the character is transcoded into the current encoding of the HALCON library (see set_system(::'filename_encoding',<encoding>:)).

When the file was opened with encoding mode 'ignore_encoding'"ignore_encoding", CharcharValchar always returns one byte without any interpretation or transcoding. This is useful for reading a file with special control bytes in a kind of raw mode. If no character can be read because the end of the file is reached, fread_charFreadChar returns the control character sequence 'eof'"eof" in CharcharValchar.

The operator fread_charFreadChar emits a low-level error message, when the next byte or byte sequence does not represent a valid code point in the specified encoding. Despite of the low-level error message, the operator will not fail and CharcharValchar will contain the next byte. Furthermore, the operator also emits a low-level error message, when the read character cannot be transcoded without loss of information into the current encoding of the HALCON library. This can only happen when the file is UTF-8 encoded and the current encoding of the HALCON library is 'locale'"locale" (see set_system(::'filename_encoding','locale':)).

Execution information๐Ÿ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

Parameters๐Ÿ”—

FileHandlefileHandlefile_handle (input_control) file โ†’ (handle)HTuple (HHandle)HFile, HTuple (IntPtr)HHandleHtuple (handle)

File handle.

CharcharValchar (output_control) string โ†’ (string)HTuple (HString)HTuple (string)strHtuple (char*)

Read character, which can be multi-byte or the control string 'eof'"eof".

Example๐Ÿ”—

(HDevelop)

* Read a text file character by character.
open_file (FileName, 'input', FileHandle)
repeat
    fread_char (FileHandle, Char)
until (Char == 'eof')
close_file (FileHandle)

Result๐Ÿ”—

If an input file is open, the operator fread_charFreadChar returns 2 (H_MSG_TRUE). Otherwise, an exception is raised. Encoding errors have no influence on the result state.

Combinations with other operators๐Ÿ”—

Combinations

Possible predecessors

open_fileOpenFile

Possible successors

close_fileCloseFile

Alternatives

fread_stringFreadString, read_stringReadString, fread_lineFreadLine

See also

open_fileOpenFile, close_fileCloseFile, fread_stringFreadString, fread_lineFreadLine

Module๐Ÿ”—

Foundation