From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Solution: Access database records - C Tutorial
From the course: Complete Guide to C Programming Foundations
Solution: Access database records
(upbeat music) - [Instructor] To read the records back to front, I'm going to need a loop. Variable X is already declared in the sample challenge code provided, but I need to decide whether to reference the records from the start or the end of the file. So I'm going to have as my first solution, reading records from the start of the file. As you see here, I've constructed a for loop at line 23. It works from nine to zero, which represent the 10 records in the file working backwards. The fseek statement uses SEEK_SET to measure the offset from the start of the file. FP is the file pointer representing the file and the offset is measured by the size of the person's structure multiplied by variable X. So this is what counts backwards. This is what moves that file position indicator backwards by one record chunk at a time. The fread function reads the record into a president structure. The size of a president's structure, only one structure needs to be read from the file indicated by file…
Contents
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Reading from a file3m 31s
-
(Locked)
Writing to a file3m 40s
-
(Locked)
Challenge: Writing and reading files1m
-
(Locked)
Solution: Writing and reading files4m 4s
-
(Locked)
Working with raw data3m 4s
-
(Locked)
Using random file access3m 21s
-
(Locked)
Challenge: Access database records56s
-
(Locked)
Solution: Access database records2m 51s
-
(Locked)
Manipulating files2m 34s
-
(Locked)
Exploring the path1m 50s
-
(Locked)
Reading a directory3m 36s
-
(Locked)
Getting file information3m 26s
-
(Locked)
Chapter challenge: Managing files1m 46s
-
(Locked)
Chapter solution: Managing files2m 50s
-
(Locked)
-
-