I’m trying to have the user input a block of text to the console that my program will read from stdin only after enter has been hit twice in a row or, said in a different way, when enter is hit on an already blank line. But, I want to continue reading from stdin so basically, only read from stdin when enter is hit while on an already blank line. Then flush and restart.
Example of user input:
Hello(\n)
World(\n)
(\n)
(Read Now)
I haven’t been able to find an input function capable of specifying this behavior.
Also, I’ve tried a few methods using single character retrieval functions but I haven’t been able to get it work correctly.
Anyone know of a way to do this elegantly?
Answer implemented:
char word[100];
int i = 0;
while ((word[i++] = getchar())!='\n' || (word[i++]=getchar())!='\n');
printf("%s",word);
Obviously buffer overflow needs to be dealt with before using this. Just an example.
Basically, you want to ignore the input until the sequence
\n\n. You can do it with: