Practice Problems
File I/O
Notice when you get compile errors (when gcc gives you an error)
vs. errors that crash the program (run-time errors)
vs. logical errors (compile and run fine but problem with your code)
- Write the code to declare and open a file for reading named coba.txt
- Write the code to declare and open a file for writing named out.txt
- What is the purpose of the fclose call on a file?
- What is the code to read the first line of the file (and that's it)?
- Write the loop to read each line from a file.
- What additional argument is required when using fprintf and fscanf as
opposed to printf and scanf?
- List 3 functions that can be used to read data from a file.
- List 3 functions that can be used to write data to a file.
- Write the code to open a file named input.txt and print an error
statement if there is a problem opening the file.