Chapter 9Reading and Writing Files
We have already taken advantage of redirection to use files as inputs and outputs. This chapter explains how to use C functions to read from or write to files.
9.1 Read from Files
A program has many ways to obtain input data, for example:
Use scanf to get data from a user through the keyboard.
Use scanf and redirection to get data from a file.
Use argc and argv to get data from the command line.
Use argv[1] as the name of an input file and read the data stored on a disk.
The first three methods have been explained in earlier chapters. This chapter explains the fourth method. After getting the file's name from argv[1], we need to open the file for reading. This is accomplished ...
Get Intermediate C Programming, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.