From the course: Master C Language Pointers
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Challenge: Saving and reading a record - C Tutorial
From the course: Master C Language Pointers
Challenge: Saving and reading a record
(upbeat music) - [Narrator] This challenge comes in two parts and requires that you create two separate programs. The first program creates a structure, fills it with data, and saves the structure to a file. The second program, surprisingly, reads the file, fills the structure, and then outputs the data read. In the saving program, the structure must be allocated as a pointer. It contains two members, a string name and an integer, age. The user is prompted to provide input for both members. The structure is then written to a file, saved.dat. The second program reads the data written by the first program. The same structure definition is allocated as a pointer, the data from saved.dat is read into the structure, and then the data is output. Now if you know how pointers work and how to write data to a file this task shouldn't be too difficult, though it may take up to 30 minutes or longer to complete.
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
-
-
-