To read and write data to and from a file—as opposed to text—, use the fwrite() and fread() functions. Both the fwrite() and fread() functions have multiple arguments to determine the value written, the size of the value written, the number of data-chunks to write, and the file handle. Multiple data chunks can be written and read at once, such as all elements in an array. The feof() function returns true when the last byte of an open file has been read.
- [Instructor] The file versions of the standard … CIO functions write text. … To read and write raw data, you use the F read … and F write functions. … and closing functions remain the same. … So, in this exercise file, 10 integers are written … to the file integers.dat, which is created … as a string constant at line five. … Then at line 10, the files open for writing … using the standard F open function with W as the mode. … A loop at line 19 writes the 10 integers. … The the F write statement at line 21 … consumes four arguments. … The first is the address of the variable … that contains the value to write. … In this case, it's variable A initialized at line 18, … and then incremented by five in line 22 … each time the loop spins. … The second argument is the size of the data chunk to write. … I use the size of operator on an integer … to obtain that size. … The third argument is the number of chunks to write, … one in this case, one integer, … and the fourth argument is the file handle, build and run. …
- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
1. Arrays and Structures
2. Characters and Strings
4. Files and the Operating System
5. The Interesting and Extraordinary
Next steps1m 52s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.