static void read_input(char *buf, int bufsize) { int i = 0; int pos = 0, maxbuf = bufsize - 1; char c; while (!feof(stdin) && (i < maxbuf) && (c = getchar()) != '\n') { buf[pos++] = c; } buf[pos++] = '\0'; }