My question is simple in the OOP languages but in the language C is not so simple.
When the user enter some text data in the console and we set for terminate char for an example ESC (the text data is multiline and we do not know when the end is).
So my question is how to read a text from the console and if the user press esc to break the loop where we read the text data?
Here is some code:
printf("Enter the source here(press ESC) : \n");
char buffer[1000][1000];
int counter = 0;
while(1)
{
if (fgets(buffer[counter],sizeof(buffer[counter]),stdin))
{
counter++;
}
}
I think the proper way to read in multiple lines of text is to terminate the input with an EOF character. In Windows I think it is ctrl+Z (I’m not sure), on unix-like systems it is ctrl+D. Many input functions in C automatically recognize it as a terminator (e.g. scanf and gets), or you can read character by character and explicitly the input char.