Week 9 Flashcards
There are two main ways the compile views a 2d array, how do they differ?
int a[][] is a cube
int **b is an array with each array item pointing to another array
How many malloc calls do we require to create a 2D array?
Two mallocs
How do you interpret the declaration int ***a?
A 3D array
A pass-by-reference of a 2D array
Given int **a: What data type if a?
A is a 2D array or a pass-by-reference of a 1D array
Given int **a: What is *a?
A pointer to an integer
Given int **a: What is **a?
**a is an integer value
What are the three modes of interacting with files?
Read the contents of a file
Write to a new file
Append to an existing file
Writing and appending operate in a similar manner. What is the main difference?
Where the writing happens.
Write -> start writing at the first byte of the file
Appending -> start writing after the last byte of the file
If the file doesn’t exist when its called, what happens?
The open call fails
What are the four buffers to your program?
Keyboard input
Screen output
disc drive output
network output
Emptying a buffer: What is the input buffer?
Reading the data
Emptying a buffer: What is the output buffer?
Filling the buffer
Printing \n (for the screen only)
Closing the file
Explicitly pushing the data to the file
What is “flushing” the buffer?
Explicitly pushing the data to the file
How are files accessed?
Through a file descriptor
The file descriptor keeps track of all the important file information. What is it?
Where does the file live?
Where am in the file?
What operations are available on the file?
What permissions do I have for the file?
Where do stdin, stdout and stderr exist?
In the open file table
FILE *fopen(char *file_path, char *mode) opens a file. What are the options for mode?
r, w, a
r - open in read mode
w - open in write mode
a - open in append mode
It’s rarely done, but adding a + to the mode allows what?
Both input and output
What does char *fgets( char *buffer, int buffer_size, FILE *file_descriptor); do?
Returns the pointer to the buffer if data was read, NULL otherwise
What does fscanf(FILE *file_descriptor, char *pattern, …); do?
Returns the number of items of the pattern matched
What does int fgetc( FILE *file_descriptor); do?
Returns unsigned char promoted to an int
What does int ungetc(int character, FILE *file_descriptor); do?
Put a read character back into the data buffer
What does feof( FILE *file_descriptor) do?
Returns zero (false) if there is more data in the file to read
What does int fprintf( FILE * file_descriptor, char *pattern, …); do?
Returns the number of bytes printed.
What does fputs( char *string, FILE *file_descriptor) do?
Returns the number of characters printed
What does fputc( int character, FILE *file_descriptor) do?
Returns the character printed or EOF
What does fflush( FILE *file_descriptor) do?
Flush the data from the buffer to the IO device
Returns 0 if the flush was successful
What does char *tmpname( char *name_buffer) do?
Get the name of the temporary file that you can open
Typically appears in the /tmp directory
The name is stored in name_buffer
Must have at least L_tmpnam butes in the array
Returns name_buffer if successful, NULL otherwise
What does FILE *tmpfile( void) do?
Open a temporary file
You won’t know the file name
Opened in w+ mode, so you can read or write to it