>To do what you want G'n'R you are going to need to put a loop using getche() (need conio.h).
I don't see why this is needed. From my interpretation of the program, the output should be something like this:
Code:
% cat test.c
#include <stdio.h>
int main ( ) {
char buffer[100];
while (fgets(buffer, 5, stdin) != NULL)
printf("|%s|\n", buffer);
return 0;
}
user: /home/user/junk
% gcc test.c; ./a.out
mookie mookie
|mook|
|ie m|
|ooki|
|e
|
^D
fgets is defined to stop reading if one of four things happen: 1) A newline is encountered. 2) EOF is encountered. 3) N-1 characters have been read (eg. the buffer is filled). 4) A read error occurs. Since G'n'R's fgets impelentation doesn't do all of this properly, we can then try to work out alternative solutions. However, there's no need to step outside the bounds of ANSI C to do it.
Code:
user: /home/user/junk
% cat test.c
#include <stdio.h>
char *reads(char *b, int lim, FILE *fd) {
int c;
int i;
i = 0;
while (i < lim - 1) {
if ((c = getc(fd)) == EOF)
break;
b[i++] = c;
if (c == '\n')
break;
}
b[i] = '\0';
if (ferror(fd) || feof(fd))
return NULL;
return b;
}
int main ( ) {
char buffer[100];
while (reads(buffer, 5, stdin) != NULL)
printf("|%s|\n", buffer);
return 0;
}
user: /home/user/junk
% gcc test.c; ./a.out
mookie mookie
|mook|
|ie m|
|ooki|
|e
|
^D