Ctrl+d

This is a discussion on Ctrl+d within the C++ Programming forums, part of the General Programming Boards category; Hello, guys! I have a question for you, how could I implement a catch of CTRL+D? I have a program, ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    17

    Ctrl+d

    Hello, guys!

    I have a question for you, how could I implement a catch of CTRL+D? I have a program, which reads strings untill is pressed CTRL+D, and I don't wanna have ^D in a console . After I press CTRL+D I have to press ENTER, and only after that my program stops . Have any ideas?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,810
    Keep reading until the EOF condition is reached.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    17
    Quote Originally Posted by laserlight View Post
    Keep reading until the EOF condition is reached.
    My program works, and I use EOF, but the problem is, that I have to catch a signal, not char, smth like CTRL+Z in Windows.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,810
    Aye, but the signal triggers EOF.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,354
    Quote Originally Posted by midnight View Post
    After I press CTRL+D I have to press ENTER, and only after that my program stops
    Ctrl-D should have an effect immediately if it is the first character on a line. If there are other characters before it on the line, you need to hit enter before the program will see it.

    Beyond that, if you want greater control over how Ctrl-D is handled, you need to reprogram the terminal device using calls like ioctl() and tcsetattr().

    (None of it has anything to do with signals).
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 07-02-2007, 12:32 AM
  2. Grabbing Ctrl and Alt key combinations
    By scorpio_IITR in forum Linux Programming
    Replies: 0
    Last Post: 04-12-2004, 03:01 AM
  3. how to capture CTRL, SHIFT and ALT ?
    By goldenrock in forum C Programming
    Replies: 3
    Last Post: 11-06-2003, 12:20 AM
  4. Recognizing ALT or Ctrl + letter
    By MethodMan in forum C Programming
    Replies: 2
    Last Post: 02-22-2003, 06:16 PM
  5. arrow keys, ctrl and alt keys
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-25-2002, 03:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21