isdigit()
i.e if(isdigit(variable))
{
do this
}
else
getchar();
isdigit()
i.e if(isdigit(variable))
{
do this
}
else
getchar();
Last edited by strickyc; 07-04-2009 at 07:49 PM.
Thanks,
When I woke up this morning, thats what I was thinking (isdigit). Then I logged on here and saw your comment, I entered it and it works well. Thanks.
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.
Code:// Enter purchase amount and verify purchase amount do { // do-while loop start printf("\n\nEnter the total purchase amount: $"); scanf("%f", &fPurchase_Amount); if (fPurchase_Amount <= 0.0) printf("\nYou did not enter a valid number, please try again"); if (isdigit(fPurchase_Amount)); else getchar(); } //end do-while loop while (fPurchase_Amount <= 0.0);
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.