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

Challenge: Saving and reading a record - C Tutorial

From the course: Master C Language Pointers

Start my 1-month free trial

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.

Contents