I'm trying to read the console after I press CTRL+C.
Now I've been able to catch the CTRL+C and then do some stuff. However I can't get the input. It's like it needs a '/n' to get the input.
Here's an example of what I enter.
If I enter "test" in the console it prints out this:"Input = "
If I enter "test" end press enter "bla" it prints out this: "Input = test"
So my question is, How do I get the first line without having to press enter?
Same goes for multiple lines in which case I need to get the last line.
Hi Rope,
I have a small piece of code.
But the problem with this is that while inputting the data the cursor does not move to new line when user enters carriage return. But after CTRL + C ur required data is getting displayed.
If somebody can sort out this then it will solve ur problem.
int c = 0;
while(true)
{
c=getch();
if(3==c)/// Int value of CTRL+C
{
raise(SIGINT);
break;
}
elseif(13==c)/// Int value of new line.
{
cout<<(char)c;
*input+="\n";
}
else
{
cout<<(char)c;
*input+=c;
}
}
I know this have some problems with it still den if it helps :-O
The answer depends entirely on what OS you are using.
Are you using Windows or Unix/Linux?
BTW. Ctrl-C is a poor choice. You'd be better off using ^Z (on Windows) or ^D (on Unix) to terminate input, then simply cin.clear() to reset the input stream.
Or even better, watch the input for a specific string, or two consecutive newlines, or something.
I had earlier tried the same[std::getchar() n std::cin.get()] instead of getch().
But that didn't fulfill the requirement of Rope [:-(].
I Think [Please clarify].... The problem with std::getchar() and std::cin.get() is that it doesn't execute the next line until I press carriage return.
Thus the inputted data is only available iff user presses carriage return, which is the main problem of Rope.