We will open a file in the 'w' mode and then truncate it. Then we accept three lines of input from the user, and append them to the file.
In the next example, we comment most of the lines of the solution and also reuse the prompt by using replacement characters.
We need not have called
truncateon the fp, since opening a file in 'w' mode automatically truncates it.