Quick C Question - checking buffer for input

This is a discussion on Quick C Question - checking buffer for input within the C Programming forums, part of the General Programming Boards category; Because of my new strategy to avoid having to use multiple threads, I won't be able to shut down my ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    Quick C Question - checking buffer for input

    Because of my new strategy to avoid having to use multiple threads, I won't be able to shut down my accept() loop by sending a message to that thread from the main thread.

    I need to check the stdin buffer for input, get that input, and then clear the buffer. If there's nothing in the buffer, I want to just move on - I can't wait for something to show up in the buffer.

    I've seen this done before and I think I've actually done it - but it's just been too long. Can someone point me in the right direction, please?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    You can use select() with fileno(stdin) in the inputset and set the timeout for select() to 0. Check man select for more info.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Thanks! Is there no standard method, too? I'm also writing a windows method, and trying not to use any third-party libraries (using OS APIs is fine, though).

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Just dig around here
    Like for example using GetNumberOfConsoleInputEvents to determine if there is any input

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick question (C/C++)
    By owi_just in forum C Programming
    Replies: 2
    Last Post: 03-19-2005, 08:44 AM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

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