Unit 3 CS 36 Flashcards
What are streams?
Streams are data buffers/collectors. The three different streams are input(keyboard), output(message or outcome after running the program), and error (message regarding wrongly written code or syntax issues). Both error and output are based on screen, and input is by keyboard
How can streams be manipulated?
Using the stdin, stdout and stderr functions from the standard library (standard in, out, and error)
How do we work with files in C?
We have to change the input and output stream files using stdin and stdout.
What are the two different ways to input and output to files?
Sequential and Random-Access
What are the two functions to manipulate files?
fgets() and fputs()
true or false: each file needs it’s own pointer?
true. to initialize a file pointer, you have to do FILE *cPtr; to point to a file structure
What does the fopen function do?
It takes a file name and a mode as it’s arguments (ex: fopen(“file.exe”, “w”); in this case, the mode of the file is write). If this file doesn’t exist, fopen creates a new file with that given name “file.exe”
File
collection of data or information that is stored on a computer’s storage. For example, a hard drive or a USB stick
What happens if fopen is equal to NULL?
That means there is an error regarding opening the file
True or false, you always have to open a file before you manipulate the file?
True, you have to use fopen and then manipulate the file, and when you are finally done manipulating everything, you close using fclose(). Remember, fopen is equal to the address of a file, meaning that you must use a pointer of a file to store this value
Let’s say you make a pointer (FILE *cPtr) and then you do cPtr = fopen(“file name”, “mode”), what does the pointer equal to if this assignment does not work?
It is equal to NULL
EOF
End of File value that tells you you have reached the end of the file that you are reading
feof(stdin)
looks for EOF (end of file) indicator
Random-Access Files
This is when a file is opened through the “wb” mode instead of “w” or “r” (write or read, and this represents binary write) and then a structure is used to fill in certain values. The file is represented in binary form
instance
The variable of a structure