Thread: Program thrown into loop when character entered instead of flaot

  1. #16
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by alekbabich View Post
    Can you impose a time limit on a command like getchar() ???

    I got the program to stop and not loop if the user enters a character rather than a number, but now the program stops and waits for the user to hit a key when they enter a number.
    ...
    One way is to schedule an alarm signal (SIGALRM) to be sent to the process after a number of seconds have elapsed, given as an argument to alarm().
    Write a signal handler that sets a flag upon receipt of SIGALRM; check the value of flag in the caller to decide whether to continue or exit the program.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    We're talking platform-specific solutions here, though. Correct me if I'm wrong.
    I don't believe there's any standard way of doing it, so the question becomes: for what OS?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Jul 2009
    Posts
    8
    I am running Windows XP, but why is it platform specific?

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There are many things C can do natively, that is with code in its standard library.
    However, there is also a lot of things that it cannot do natively, simply because there is no standard pre-existing code that does this.
    That is when we must turn to code that exists on operating systems that can do this for us.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C keep a loop going whilst program continues on
    By fortune2k in forum C Programming
    Replies: 6
    Last Post: 03-11-2009, 08:44 AM
  2. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  3. Using While Loop to write a program
    By Cyberman86 in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2008, 12:52 PM
  4. Unexplained "unhandled exception"
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 04-19-2007, 11:19 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM