I am new for this forum. I have a question about a for loop in c language(sorry it is not a c++ question): I try to get 5 characters one by one from the keyboard and print them out. The for loop repeats 5 times BUT only accept 3 characters from keyboard. I wonder if anyone there can explains why.
It is because the console input is line buffered. The second and fourth characters are the newline character (\n). Try responding with all five characters when it asks for 1.
When I feed the program five letters(a, b,c,d,e) all at once as 'abcde' followed by 'Enter' key the program runs and prints out all letters one by one. But this behavior is different from what I originally want: I want to do it interactively: enter one letter then print out one letter, and so on. How do I modify the codes to achieve this goal?
The getch() function is non-standard, and probably only works as you have it because you are using an old Borland or MS compiler, which let you use it without properly #including <conio.h>.
If you use the curses library, as I suggest, then you will have standardized, cross-platform code that allows you to do what you want.