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 Files

To read from a file in C, you can use the fgets() function. It was first introduced in Chapter 5 as a reliable way to read numeric input from the keyboard. The syntax for using fgets() is

fgets (var, length, pointer);

The function reads up to length amount of data from the file and assigns this to var. You should take precautions to ensure that the function does not attempt to read in more data than can be stored in the variable. A reliable way to do this is to use the sizeof() operator:

fgets (var, sizeof(var), pointer);

Line and File Endings

One of the nice things about C with respect to working with files is that it will automatically convert line endings. Different operating systems use different characters to mark ...

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