O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Line-Based Multicharacter I/O

If you want to write out a whole line of characters (a string), you can do so with a single call to fputs. The definition of fputs is as follows:

int fputs ( const char * string, FILE * stream )

This function ignores whitespace and could have equally well been used in the variable-length string-reading and -writing example. This being the case, you might also have replaced the reading facility with a single call to the companion function fgets instead of multiple calls to fscanf. The definition of fgets is as follows:

int fgets ( char * string, int max_length, FILE * stream )

This would seem to be an elegant solution; fgets can read in a number of characters (limited by the max_length parameter) from an open ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required