Skip to content

stdio.h

Type Definitions

Typedef Datatype Description
size_t unsigned int Result of the sizeof keyword.
FILE object Suitable for storing information for a file stream.
fpos_t object Suitable for storing any position in a file.

Methods

Return Method
int printf( const char *format, ... )
int puts( const char *str )
int scanf( const char *format, ... )
char* gets( char *str )
FILE* fopen( const char *filename, const char *mode )
int fclose( FILE *stream )
size_t fwrite( const void *ptr, size_t size, size_t nmemb, FILE *stream )
int fprintf( FILE *stream, const char *format, ... )
int fputc( int char, FILE *stream )
int fputs(const char *str, FILE *stream)
size_t fread( void *ptr, size_t size, size_t nmemb, FILE *stream )
int fscanf( FILE *stream, const char *format, ... )
int fgetc( FILE *stream )
char* fgets( char *str, int n, FILE *stream )
int fseek( FILE *stream, long int offset, int whence )
long int ftell( FILE *stream )
void rewind( FILE *stream )

Method Descriptions

int printf( const char *format, ... )

Sends formatted output to stdout.


int puts( const char *str )

Writes a string to stdout up to but not including the null character. A newline character is appended to the output.


int scanf( const char *format, ... )

Reads formatted input from stdin.


char *gets( char *str )

Reads a line from stdin and stores it into the string pointed to by, str. It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.


FILE *fopen( const char *filename, const char *mode )

Opens the filename pointed to by filename using the given mode.

Parameter Description
filename string containing the name of the file to be opened.
mode string containing a file access mode.
mode Description
"r" Opens a file for reading. The file must exist.
"w" Creates an empty file for writing. If a file with the same name already exists, its content is erased and the file is considered as a new empty file.
"a" Appends to a file. Writing operations, append data at the end of the file. The file is created if it does not exist.
"r+" Opens a file to update both reading and writing. The file must exist.
"w+" Creates an empty file for both reading and writing.
"a+" Opens a file for reading and appending.

int fclose( FILE *stream )

Closes the stream. All buffers are flushed.


size_t fwrite( const void *ptr, size_t size, size_t nmemb, FILE *stream )

Writes data from the array pointed to by ptr to the given stream.


int fprintf( FILE *stream, const char *format, ... )

Sends formatted output to a stream.


int fputc( int char, FILE *stream )

Writes a character (an unsigned char) specified by the argument char to the specified stream and advances the position indicator for the stream.


int fputs( const char *str, FILE *stream )

Writes a string to the specified stream up to but not including the null character.


size_t fread( void ptr, size_t size, size_t nmemb, FILE *stream )

Reads data from the given stream into the array pointed to by ptr.


int fscanf( FILE *stream, const char *format, ... )

Reads formatted input from a stream.


int fgetc( FILE *stream )

Gets the next character (an unsigned char) from the specified stream and advances the position indicator for the stream.


char *fgets( char *str, int n, FILE *stream )

Reads a line from the specified stream and stores it into the string pointed to by str. It stops when either (n-1) characters are read, the newline character is read, or the end-of-file is reached, whichever comes first.


int fseek( FILE *stream, long int offset, int whence )

Sets the file position of the stream to the given offset.

int whence Description
1 SEEK_SET Beginning of file
2 SEEK_CUR Current position of the file pointer
3 SEEK_END End of file

long int ftell( FILE *stream )

Returns the current file position of the given stream.


void rewind( FILE *stream )

Sets the file position to the beginning of the file of the given stream.