Lab 2: File Operations and Unbuffered I/O

Preliminaries

Topics:
  1. Buffered vs Unbuffered I/O
  2. File operations

Part 1

What's the difference between buffered and unbuffered I/O? When to use which?
Problem:
  1. Write a program that reads test.txt in.
  2. Add 100 to the number in the file.
  3. Print out the new value.
  4. Example:
    • $ echo "sum: 200" > test.txt
    • $ cat test.txt
    • $ ./my_program
    • $ 300

1.1) Using Unbuffered I/O:
Download the code here

1.2) Using Standard I/O:
Can you rewrite the program using the following stdio routines?

Part 2

The fstat system call
It's used to extract the following information about a file: Find more about fstat here
Problem:
Let's write a program that prints out the above information about the file whose name is passed to the program as an argument.
Download the code here

Author: Sasan Golchin