From the course: Master C Language Pointers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Saving pointers and buffers - C Tutorial
From the course: Master C Language Pointers
Saving pointers and buffers
- [Instructor] When saving a buffer to a file, ensure that you save the data and not the pointer. To illustrate consider this code. Storage for 10 integers is allocated and then filled. A file is opened at line 25, and key to the operation is the fwrite function at line 33. The arguments are the address of the data chunk. Pointer base in this case. The size of each item to write integer and then the quantity, 10 integers and the file pointer. Build and run. And 10 integers are written to the file integers.dat. The output is in informative, but did it work? This code reads the data file using a similar technique as shown in the first exercise. So a buffer is allocated here in line 10, a file is open for reading here at line 18, and at line 26 the fread function reads in the 10 integers. Integers or output in the for loop down here at line 39. Build and run, and it all works, thank you. Where this operation can go…
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.
Contents
-
-
-
-
Comparing arrays and pointers3m 36s
-
Allocating storage3m 29s
-
Exploring allocation functions4m 58s
-
Accessing the buffer3m 41s
-
Working with pointers in structures2m 18s
-
Creating structure pointers3m 29s
-
Saving pointers and buffers4m 31s
-
Challenge: Saving and reading a record1m 6s
-
Solution: Saving and reading a record2m 15s
-
-
-