1

I have been trying to write a program that accepts user input as they type in. I need these input strings to do certain task by calling an external executable as soon as the word is separated by space. I tried using scanf(). Though the words can be read, the executable is executed only after ENTER is pressed. i.e,instead of word by word, the program is executing the desired call line by line only. Is there anyway to make the program to execute the call word by word? That is, when the SPACE is pressed, could the call be done?

If not possible in C, is it possible in any other programming language like python, c++ etc?

FaizFizy
  • 459
  • 5
  • 15
izza
  • 13
  • 7

1 Answers1

1

The problem is that your terminal is buffering the line until you hit enter. The input doesn't even go to your program until you hit enter, so there is no way around that without tweaking the way your terminal works by putting it into raw mode. Answers to the following question go into detail about making your terminal not do line buffering: How to avoid press enter with any getchar().

Community
  • 1
  • 1
skyler
  • 1,487
  • 1
  • 10
  • 23
  • so is that the case with any other programming language? – izza Aug 19 '15 at 05:57
  • For almost any programming language you can find a library that can handle keyboard input as soon as you press a key. However, I do not know of any way for the type of program to work on the terminal without messing with the terminal's configuration. – skyler Aug 19 '15 at 06:00