Introduction In many, many places throughout the code base, there is a need to read in lines of text, one line at a time, either from a le or from stdin. In the past, this has often been done with the standard C library's fgets() function. However, fgets() su*ers from a serious design aw in that it includes the line terminator (just a plain line-feed character on Unix-like systems) in the returned string. The line terminator is almost never wanted, so, everywhere that fgets() is used, one usually needs to add code to strip the line terminator. The GetLine() function, dened in getLine.h and implemented in getLine.cpp, is designed to be a direct, drop-in replacement for fgets(). It takes the exact same parameters, returns the same return value, and actually calls fgets() internally to implement the read. The di*erence is that GetLine() strips the line terminator o* the returned string.
Revised: September 30, 2014 |
Published: May 1, 2010