Skip to Main Content
C Programming: Visual Quickstart Guide
book

C Programming: Visual Quickstart Guide

by Larry Ullman, Marc Liyanage
October 2004
Beginner content levelBeginner
408 pages
9h 24m
English
Peachpit Press
Content preview from C Programming: Visual Quickstart Guide

Reading from Binary Files

As you might expect, reading from binary files is just the opposite of writing to them. To do so, you'll make use of the fread() function:

fread (var_pointer, size, blocks, fp);

The first argument is a pointer to, or the address of, the variable to which the read data should be assigned. The second value is the size (in terms of bytes) of one block of data to be read in. This value should correspond to the size of the receiving variable. The blocks argument works like its counterpart in fwrite(): dictating how many chunks of data to read in. Finally, the file pointer is referenced.

In our next example, we use fread()to read the entire contents of the data file back into an array. In the subsequent example, fread() ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intermediate C Programming

Intermediate C Programming

Yung-Hsiang Lu
Data Structures Using C

Data Structures Using C

Samir Kumar Bandyopadhyay, Kashi Nath Dey

Publisher Resources

ISBN: 0321287630Purchase book