10 Flashcards
What is the function prototype for getchar?
int getchar(void);
What does getchar do?
Gets a single character from stdin.
What is the function prototype for putchar?
int putchar(int c);
What does putchar do?
Prints a single character to stdout.
What does putchar do if it is not given an unsigned char?
It returns an error value.
What does getchar return when it reaches the end of input?
EOF. This is a macro and may vary across platforms.
What is the return value of fopen?
FILE*
What are the three modes of file access?
‘r’, ‘w’, ‘a’
What is the ‘r’ mode of file access used for?
Reading.
What is the ‘w’ mode of file access used for?
Writing.
What is the ‘a’ mode of file access used for?
Appending data to a file.
What is the difference between ‘write’ and ‘append’ mode?
Write deletes the contents of the file if it already exists, whereas append starts writing to the end of the file.
What function is used to close a FILE*?
fclose
What is the function prototype for fclose?
int fclose(FILE *fp);
What is the function prototype for fopen?
FILE* fopen(const char* fname, const char* mode);
Which one of these is the correct function for writing a character to a file?
fputc
fputchar
fputc
Which one of these is the correct function for reading a character from a file?
fgetc
fgetchar
fgetc
What is the data type of stdin, stdout and stderr?
FILE*
What is the function prototype for ungetc?
int ungetc(int char, FILE* stream);
What does the function ‘ungetc’ do?
It returns a single character back into a stream. Useful for parsers etc.
What does feof do?
Returns zero if the stream is at the end of the file.
Which of these three streams in unbuffered?
stdin
stdout
stderr
stderr
How are each of these streams buffered?
stdin
stdout
stderr
stdin and stdout are both line-buffered.
stderr is unbuffered.
What does the fflush function do?
Flushes the buffer of a FILE*