stdio.h Flashcards
What is fputs()?
Declaration:
int fputs(const char *str, FILE *stream);
Writes a string to the specified stream up to but not including the null character.
On success a nonnegative value is returned. On error EOF is returned.
What are stderr, stdin, and stdout?
These are pointers to FILE types which correspond to the standard error, standard input, and standard output streams.
What is fseek()?
Declaration:
int fseek(FILE *stream, long int offset, int whence);
Sets the file position of the stream to the given offset. The argument offset signifies the number of bytes to seek from the given whence position. The argument whence can be:
SEEK_SET Seeks from the beginning of the file.
SEEK_CUR Seeks from the current position.
SEEK_END Seeks from the end of the file.
On a text stream, whence should be SEEK_SET and offset should be either zero or a value returned from ftell.
The end-of-file indicator is reset. The error indicator is NOT reset.
On success zero is returned. On error a nonzero value is returned.
What is freopen()?
Declaration:
FILE *freopen(const char *filename, const char *mode, FILE *stream);
Associates a new filename with the given open stream. The old file in stream is closed. If an error occurs while closing the file, the error is ignored. The mode argument is the same as described in the fopen command. Normally used for reassociating stdin, stdout, or stderr.
On success the pointer to the stream is returned. On error a null pointer is returned.
What is:
int vprintf(const char *format, va_list arg);
Sends formatted output to stdout using an argument list
What is:
int vsprintf(char *str, const char *format, va_list arg);
Sends formatted output to a string using an argument list
What are SEEK_CUR, SEEK_END, and SEEK_SET?
These are used in the fseek function.
What is getc()?
Declaration:
int getc(FILE *stream);
Gets the next character (an unsigned char) from the specified stream and advances the position indicator for the stream.
This may be a macro version of fgetc.
On success the character is returned. If the end-of-file is encountered, then EOF is returned and the end-of-file indicator is set. If an error occurs then the error indicator for the stream is set and EOF is returned.
What is TMP_MAX?
The maximum number of unique filenames that the function tmpnam can generate.
What is putchar()?
Declaration:
int putchar(int char);
Writes a character (an unsigned char) specified by the argument char to stdout.
On success the character is returned. If an error occurs, the error indicator for the stream is set and EOF is returned.
What is remove()?
Declaration:
int remove(const char *filename);
Deletes the given filename so that it is no longer accessible (unlinks the file). If the file is currently open, then the result is implementation-defined.
On success zero is returned. On failure a nonzero value is returned.
What is fopen()?
Declaration:
FILE *fopen(const char *filename, const char *mode);
Opens the filename pointed to by filename. The mode argument may be one of the following constant strings:
r read text mode
w write text mode (truncates file to zero length or creates new file)
a append text mode for writing (opens or creates file and sets file pointer to the end-of-file)
rb read binary mode
wb write binary mode (truncates file to zero length or creates new file)
ab append binary mode for writing (opens or creates file and sets file pointer to the end-of-file)
r+ read and write text mode
w+ read and write text mode (truncates file to zero length or creates new file)
a+ read and write text mode (opens or creates file and sets file pointer to the end-of-file)
r+b or rb+ read and write binary mode
w+b or wb+ read and write binary mode (truncates file to zero length or creates new file)
a+b or ab+ read and write binary mode (opens or creates file and sets file pointer to the end-of-file)
If the file does not exist and it is opened with read mode (r), then the open fails.
If the file is opened with append mode (a), then all write operations occur at the end of the file regardless of the current file position.
If the file is opened in the update mode (+), then output cannot be directly followed by input and input cannot be directly followed by output without an intervening fseek, fsetpos, rewind, or fflush.
On success a pointer to the file stream is returned. On failure a null pointer is returned.
What is getchar()?
Declaration:
int getchar(void);
Gets a character (an unsigned char) from stdin.
On success the character is returned. If the end-of-file is encountered, then EOF is returned and the end-of-file indicator is set. If an error occurs then the error indicator for the stream is set and EOF is returned.
What is setvbuf()?
Declaration:
int setvbuf(FILE *stream, char *buffer, int mode, size_t size);
Defines how a stream should be buffered. This should be called after the stream has been opened but before any operation has been done on the stream. The argument mode defines how the stream should be buffered as follows:
_IOFBF Input and output is fully buffered. If the buffer is empty, an input operation attempts to fill the buffer. On output the buffer will be completely filled before any information is written to the file (or the stream is closed).
_IOLBF Input and output is line buffered. If the buffer is empty, an input operation attempts to fill the buffer. On output the buffer will be flushed whenever a newline character is written.
_IONBF Input and output is not buffered. No buffering is performed.
The argument buffer points to an array to be used as the buffer. If buffer is a null pointer, then setvbuf uses malloc to create its own buffer.
The argument size determines the size of the array.
On success zero is returned. On error a nonzero value is returned.
What is rename()?
Declaration:
int rename(const char *old_filename, const char *new_filename);
Causes the filename referred to by old_filename to be changed to new_filename. If the filename pointed to by new_filename exists, the result is implementation-defined.
On success zero is returned. On error a nonzero value is returned and the file is still accessible by its old filename.
What is fsetpos()?
Declaration:
int fsetpos(FILE *stream, const fpos_t *pos);
Sets the file position of the given stream to the given position. The argument pos is a position given by the function fgetpos. The end-of-file indicator is cleared.
On success zero is returned. On error a nonzero value is returned and the variable errno is set.
What is typedef size_t?
The unsigned integer result of the sizeof keyword.
What is tmpfile()?
Declaration:
FILE *tmpfile(void);
Creates a temporary file in binary update mode (wb+). The tempfile is removed when the program terminates or the stream is closed.
On success a pointer to a file stream is returned. On error a null pointer is returned.
What is rewind()?
Declaration:
void rewind(FILE *stream);
Sets the file position to the beginning of the file of the given stream. The error and end-of-file indicators are reset.
What is ftell()?
Declaration:
long int ftell(FILE *stream);
Returns the current file position of the given stream. If it is a binary stream, then the value is the number of bytes from the beginning of the file. If it is a text stream, then the value is a value useable by the fseek function to return the file position to the current position.
On success the current file position is returned. On error a value of -1L is returned and errno is set.
What is perror()?
Declaration:
void perror(const char *str);
Prints a descriptive error message to stderr. First the string str is printed followed by a colon then a space.
Then an error message based on the current setting of the variable errno is printed.