On Fri, Feb 25, 2011 at 11:09 AM, Kenneth Gonsalves <law...@thenilgiris.com> wrote: > hi, > > I have a C program that counts newlines. Running it from the console, > the newline counter increments each time enter is pressed. Now I need to > send EOF to make the program print the total number of lines. How do I > do that? > > ref: K&R 1.5.3
Okay. Normally you can look for getch() == EOF which is defined in some stdio.h or some such header file. And you press Ctrl-D which is end of file in UNIX. But that need not be the case. Now the issue is that you need to convert the console into raw mode instead of cooked mode. Only then it will work. Normally an input is taken only when you type enter. But in vi/vim and less you find that it reacts even without pressing enter. How? The terminal is in raw mode. There are certain terminal line settings ICANON and friends invoked with the fcntl(2) and friends. I usually go this difficult way but apparently there are some higher level wrappers in nCurses. -Girish _______________________________________________ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc