#include #include "string_util.h" /** * Reads from standard input until end of line or file, saving up * to the given number of characters in the given string. The string * will be null-terminated. The newline is not saved in s. * * @param s a string with space to hold max+1 characters * @param max a nonnegative integer */ void read_line(char s[], int max) { int count = 0; // number of chars read int ch; while ((ch = getchar()) != EOF && ch != '\n') { if (count < max) { s[count] = ch; } count++; } s[(count > max ? max : count)] = '\0'; }