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

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