From the course: C Standard Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
File access example
- [Instructor] Now let's see an application that reads from a file and writes into the same file. I will use Get C to read each character from the file and I will use F Print F to write something into the file. And what I want to do is to print out the exact file to the screen, so what I will do is read each character from the file and send it out to the screen. And later, I will report in the file how many characters I found. That's why you can see an integer variable called Counter in line four. So, let's get started. So first let me declare a file variable, which will actually be a pointer called f and I will assign a new file to it by means of the f open function. Now remember, this function takes in two strings. The first one is the file name and I will name this file names.txt I already have a file with a bunch of names available for this. And the second argument is the access mode. For this example, I will use r+ which means reading access with added writing access. Now let me…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.