Press Ctrl-D whiling inputting

Press Ctrl-D whiling inputting

Post by Ng Yuet Yeung Eno » Fri, 19 Jan 1996 04:00:00



I write a program:

#include <stdio.h>
main()
{
   char str[81];
   while(1)
   {
      gets(str);
      printf("You input: %s\n",str);
   }

Quote:}

My question is why it causes infinitely loop after I press Ctrl-D.
Is there any solution about this?  Thanks.

--
     +------------------------------------------------------------+
    / \   Trying to maintain a good friendship with all people   / \
   /   + - - - - - - - - - - - - - - - - - - - - - - - - - - - -/ - +


+------------------------------------------------------------+   /
 \ /Home Page: http://susis.ust.hk/~enoch                     \ /
  +------------------------------------------------------------+

 
 
 

Press Ctrl-D whiling inputting

Post by Ng Yuet Yeung Eno » Mon, 22 Jan 1996 04:00:00



: #include <stdio.h>
: main()
: {
:    char str[81];
:    while(1)
:    {
:       gets(str);
:       printf("You input: %s\n",str);
:    }
: }

I think my question has a bit confusing.  My question is, if I want to
get a string again after the user press Ctrl-D.  What can I do?  It is
because after user press Ctrl-D and I ask for gets again, it will
return NULL again.  Sorry about that. Thanks.

--
     +------------------------------------------------------------+
    / \   Trying to maintain a good friendship with all people   / \
   /   + - - - - - - - - - - - - - - - - - - - - - - - - - - - -/ - +


+------------------------------------------------------------+   /
 \ /Home Page: http://susis.ust.hk/~enoch                     \ /
  +------------------------------------------------------------+

 
 
 

Press Ctrl-D whiling inputting

Post by Stephen Bayn » Tue, 23 Jan 1996 04:00:00




: I think my question has a bit confusing.  My question is, if I want to
: get a string again after the user press Ctrl-D.  What can I do?  It is
: because after user press Ctrl-D and I ask for gets again, it will
: return NULL again.  Sorry about that. Thanks.

man clearerror.

But you may need to check that the input is a terminal before you use
it and try and get more input. (Consider what will happen if the input
is coming from a file.)

--

Philips Semiconductors Ltd
Southampton                                 My views are my own.
United Kingdom

 
 
 

Press Ctrl-D whiling inputting

Post by Jason C. Aust » Tue, 23 Jan 1996 04:00:00



=> I think my question has a bit confusing.  My question is, if I want to
=> get a string again after the user press Ctrl-D.  What can I do?  It is
=> because after user press Ctrl-D and I ask for gets again, it will
=> return NULL again.  Sorry about that. Thanks.

        Try using the clearerr() function on stdin and then read
again.  It sets the EOF indicator back to zero.
--
Jason C. Austin

WWW:   http://gis-www.larc.nasa.gov/~jason

 
 
 

1. Ctrl-C & Ctrl-D don't work if -nolineediting is in effect

Hi,

If bash is invoked with -nolineediting, then it should skip the
getline lib and depend on the tty's built-in editing functions.
However, I have found that Ctrl-? (erase) and Ctrl-U (kill) work
but Ctrl-C (intr) and Ctrl-D (eof) don't, although they are
the current settings in the tty settings. Why don't they work?

Thanks in advance for any info!

ps, my tty settings are pretty standard. The output of 'stty -a' is:

speed 9600 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase =
^W;
lnext = ^V; flush = ^O; min = 1; time = 0;

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Power Mangment Problems

3. what to do with xserver restarting when I press Ctrl-AltF1?

4. Where is Cyrix 6x86 patch?

5. "press any key..." user input

6. #include <linux/sched.h>

7. Reading input in C without pressing 'enter'

8. How to "switch system profile" in Redhat 7.3

9. More good press for Linux that's bad press for MS.

10. [press@apache.org: PRESS RELEASE: ASF Reaches Agreement with Sun to Allow Open Source Java Implementations]

11. [press@apache.org: PRESS RELEASE: ASF Reaches Agreement with

12. CTRL-d NOT recognized at boot time

13. Why don't ctrl c and ctrl z work on OS5???