Implements basic file input operations. Attempting to open or construct FileInput for a non-existing file will corrupt the file (FileInput_is_bad returns TRUE)
Creates an empty input file stream object.
#include <cybiko.h> ... { char tenth_byte; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "game.save" ) ) { FileInput_seek( &file_input, 10, SEEK_SET ); tenth_byte = FileInput_read_byte( &file_input ); } ... FileInput_dtor( &file_input, LEAVE_MEMORY ); ... }
Creates an input file stream object for a file with the specified name.
#include <cybiko.h> ... char tenth_byte; struct FileInput file_input; ... FileInput_ctor_Ex( &file_input, "game.save"); ... FileInput_seek( &file_input, 10, SEEK_SET ); tenth_byte = FileInput_read_byte( &file_input ); ... FileInput_dtor( &file_input, LEAVE_MEMORY ); ...
Destructor.
#include <cybiko.h> ... { char tenth_byte; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "game.save" ) ) { FileInput_seek( &file_input, 10, SEEK_SET ); tenth_byte = FileInput_read_byte( &file_input ); } ... FileInput_dtor( &file_input, LEAVE_MEMORY ); } ...
Returns the stream's current state.
#include <cybiko.h> ... { char tenth_byte; long size; long sum = 0; long index = 0; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "values.txt" ) ) { while( ! ( FileInput_get_flags( &file_input ) & FLAG_EOF ) ) { sum += (long)FileInput_read_byte( &file_input ); index ++; } } ... FileInput_dtor( &file_input, LEAVE_MEMORY ); } ...
Returns the stream size (if applicable).
#include <cybiko.h> ... { char tenth_byte; long size; long index; long sum = 0; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "values.txt" ) ) { size = FileInput_get_size( &file_input); for( index = 0; index < size; index++ ) { sum += (long)FileInput_read_byte( &file_input ); } } ... FileInput_dtor( &file_input, LEAVE_MEMORY ); } ...
Returns TRUE if the BAD flag is set (stream is bad).
#include <cybiko.h> ... struct FileInput file_input; ... FileInput_ctor_Ex( &file_input , "values.txt"); if ( ! FileInput_is_bad( &file_input ) ) { // Success. ... } ...
Returns TRUE if the EOF flag is set (stream reached end-of-file).
#include <cybiko.h> ... { char tenth_byte; long size; long sum = 0; long index = 0; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "values.txt" ) ) { while( ! FileInput_is_eof( &file_input ) ) { sum += (long)FileInput_read_byte( &file_input ); index ++; } } ... FileInput_dtor( &file_input, LEAVE_MEMORY ); } ...
Returns TRUE if the BAD flag is not set (stream is good).
#include <cybiko.h> ... struct FileInput file_input; ... FileInput_ctor_Ex( &file_input , "values.txt"); if( FileInput_is_good( &file_input ) ) { // Success. ... } ...
Opens an input stream for the file with the specified name.
#include <cybiko.h> ... { char tenth_byte; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "game.save" ) ) { FileInput_seek( &file_input, 10, SEEK_SET ); tenth_byte = FileInput_read_byte( &file_input ); } ... FileInput_dtor( &file_input, LEAVE_MEMORY ); } ...
Reads a specified number of bytes from the stream.
#include <cybiko.h> ... struct FileInput file_input; struct score_t high_scores[10]; ... FileInput_ctor( &file_input ); if( FileInput_open( &file_input, "game.save" ) ) ... Input_read( &file_input, high_scores, sizeof(high_scores) ); ... Input_dtor( &file_input, LEAVE_MEMORY ); ...
Reads the next byte from the stream.
#include <cybiko.h> ... { char tenth_byte; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "game.save" ) ) { FileInput_seek( &file_input, 10, SEEK_SET ); tenth_byte = FileInput_read_byte( &file_input ); } ... FileInput_dtor( &file_input, LEAVE_MEMORY ); } ...
Seeks to the specified position, then returns the sought position.
If the stream supports a seek operation, it seeks to the specified position in the specified mode. If the requested seek operation can not be done (not supported or wrong parameters), -1 will be returned. Seeking prior to the beginning of the stream sets the pointer to the stream's first byte. Seeking after the end of the stream sets the pointer to the end of stream just after the stream's last byte.
#include <cybiko.h> ... { char tenth_byte; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "game.save" ) ) { FileInput_seek( &file_input, 10, SEEK_SET ); tenth_byte = FileInput_read_byte( &file_input ); } ... FileInput_dtor( &file_input, LEAVE_MEMORY ); } ...
Seeks an input stream.
#include <cybiko.h> ... { char tenth_byte; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "game.save" ) ) { FileInput_seekg( &file_input, 10, SEEK_SET ); tenth_byte = FileInput_read_byte( &file_input ); } ... FileInput_dtor( &file_input, LEAVE_MEMORY ); } ...
Returns the stream's current position.
#include <cybiko.h> ... char tenth_byte; struct FileInput file_input; long cur_pos; ... FileInput_ctor_Ex( &file_input, "game.save"); ... FileInput_seek( &file_input, 10, SEEK_SET ); tenth_byte = FileInput_read_byte( &file_input ); // cur_pos will be equal to 11. cur_pos = FileInput_tell( &file_input ); ... FileInput_dtor( &file_input, LEAVE_MEMORY ); ...
Returns the stream's position.
#include <cybiko.h> ... { char tenth_byte; long current_pos; struct FileInput file_input; ... FileInput_ctor( &file_input ); ... if( FileInput_open( &file_input, "game.save" ) ) { FileInput_seekg( &file_input, 10, SEEK_SET ); tenth_byte = FileInput_read_byte( &file_input ); } // The current_pos value will be equal to 11. current_pos = FileInput_tellg( &file_input ); ... FileInput_dtor( &file_input, LEAVE_MEMORY ); } ...