[prog] C problem I am unable to solve

Conor Daly conor.daly-linuxchix at cod.homelinux.org
Fri May 13 05:58:36 EST 2005


On Thu, May 12, 2005 at 02:28:58PM -0400 or so it is rumoured hereabouts, 
Angelina Carlton thought:
> 
> Well im embarressed to say how many evenings I have picked at this
> program without any success, and being too stubborn to ask for help
> sometimes isnt helping my self-education effort much either. 

Nah, this is just standard C programming!  I've found it useful, after
a period of banging my head on the keyboard, to ask someone else to have a
look at my code.  Typically, they'll point and say "what does that do?"
whereupon, I'll explain what it's supposed to do and see why it doesn't do
it!
 
Interestingly, I always have trouble with EOFs and there are probably ten
different bodges scattered through bits of my code.  There was one where I
compared five previous copies of the read line to decide if it was the
same one or some such madness!!

Now, I started poking at this 'cos there's one thing bothering me.  The
'more' program (which this is trying to implement) accepts a single
keystroke as input while none of scanf(), getchar(), fgetc() will do.
This is the source of the multiple pages of output problem.  Angelina's
"press any key to exit" works but doesn't escape the need to hit <ENTER>
every time.  Any of the earlier implementations will display one block of
20 lines for each keypress before the <ENTER>.  If you type '1234'<ENTER>,
100 lines of text will be displayed.  However, more(1) uses the
'termios.h' terminal interface for such stuff.  I'm wondering if there's
an ordinary way in C to just grab a single char from stdin without waiting
for an <ENTER> keystroke? 

Conor
-- 
Conor Daly <conor.daly at oceanfree.net>

Domestic Sysadmin :-)
---------------------
Hobbiton.cod.ie
 19:21:33  up 41 days,  3:38,  1 user,  load average: 0.00, 0.00, 0.00


More information about the Programming mailing list