/* Name: util.h Purpose: Utility functions related to reading strings from a file Author: Bill Slough */ #ifndef UTIL_H #define UTIL_H #include #include /* Read and store one line of input from a given input file. Return NULL if stream is at eof or there was a read error; otherwise returns a pointer to a null-terminated string of the correct size. The terminating newline character marking the end of the line is not stored in the resulting string. */ char *read_line(FILE *fp); /* read all lines from a given input file */ char **read_lines(FILE *fp); /* safely allocate a block of storage, aborting program if not possible */ void *safe_malloc(size_t size); /* safely reallocate a block of storage, aborting program if not possible */ void *safe_realloc(void *ptr, size_t size); /* display all lines in a NULL-terminated array of strings */ void display_lines(char *p[ ]); /* display all lines in a NULL-terminated array of strings in reverse order */ void display_lines_in_reverse(char *p[ ]); /* counts the number of lines stored in a NULL-terminated array of strings */ int count_lines(char *p[ ]); #endif