I would like to flush my buffer after every three characters are typed in (instead of the \n). What would be the proper way to change the line-buffer trigger to be from being \n to being every 3 chars?
So far I have something like this:
#include<stdio.h>
#define CHAR_BUFFER 3
int main(void)
{
    int ch;
    int num=0;
    while ((ch = getchar()) != EOF) {
        if (ch == '\n') continue; // ignore counting newline as a character
        if (++num % CHAR_BUFFER == 0) {
            printf("Num: %d\n", num);
            fflush(stdout);
            putchar(ch);
            
        }
    }
    return 0;
}
What the program currently produces is:
$ main.c
Hello how are you?
Num: 3
lNum: 6
 Num: 9
wNum: 12
rNum: 15
yNum: 18
?
So instead of printing out all three chars, it seems to only grab the last one. What would be the correct way to do this?
Here are two examples of what I want:
H<enter>
// [nothing returned since we have not yet hit our 3rd character]
el<enter>
Hel // [return 'Hel' since this is now a multiple of three]
 
     
    