/* * Copyright 2011 Steven Gribble * * This file is the solution to an exercise problem posed during * one of the UW CSE 333 lectures (333exercises). * * 333exercises is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 333exercises is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 333exercises. If not, see . */ #ifndef _READLINE_FROM_FILE_H_ #define _READLINE_FROM_FILE_H_ // Reads a line (a series of characters terminated by // a newline, or the end of file) from file F. If the line // ends in a newline, ReadNextLine strips the newline. // Allocates memory for the line, and copies the line // (plus a NULL terminator) into the the allocated memory. // Returns a pointer to the allocated string through // the output parameter retbuf; the caller is responsible // for eventually free()'ing that memory. // // Arguments: // // - f: a stdio FILE object to read from // // - retbuf: an output parameter through which a // pointer to the returned buffer is passed. // // Returns: // // - 0 on failure (end of file, or out of memory), // in which case nothing is allocated and nothing // is returned through retbuf. Caller is responsible // for fclose()'ing f in this case. // // - 1 on success int ReadNextLine(FILE *f, char **retbuf); #endif // _READLINE_FROM_FILE_H_