linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Help: need to prevent infinite loop
@ 2006-01-17  4:36 Shriramana Sharma
  2006-01-17  7:14 ` Jesse Ruffin
  0 siblings, 1 reply; 7+ messages in thread
From: Shriramana Sharma @ 2006-01-17  4:36 UTC (permalink / raw)
  To: linux-c-programming

Hello. I have the following code:

#include "stdio.h"
int repeatinput;
int jday, jmon, jyear;
enum boolean { FALSE, TRUE };
void main(void)
{
	do
	{
		repeatinput = FALSE;
		printf("Date as YYYY-MM-DD     : ");
		if (scanf("%d-%d-%d", &jyear, &jmon, &jday) < 1) repeatinput = TRUE;
		if (jyear < 1800 || jyear > 2399) repeatinput = TRUE;
		if (repeatinput) printf ("Please enter a valid date.\n");
	}
	while (repeatinput);
	printf ("Thanks for entering a valid date.\n");
}

If I compile it with gcc and execute it, and press an arrow key at the input 
prompt and press enter, I get an infinite loop giving the date prompt and 
saying "Please enter a valid date".

Wonder what's wrong with the code? Should not, at the second execution of the 
loop, it wait for me to enter a correct input?

Thanks for your feedback.

-- 

Penguin #395953 resides at http://samvit.org
subsisting on SUSE Linux 10.0 with KDE 3.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-01-23  5:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-17  4:36 Help: need to prevent infinite loop Shriramana Sharma
2006-01-17  7:14 ` Jesse Ruffin
2006-01-18 16:24   ` Shriramana Sharma
2006-01-18 16:33     ` Steve Graegert
2006-01-22 10:20   ` Glynn Clements
2006-01-22 11:28     ` Jesse Ruffin
2006-01-23  5:57       ` Jesse Ruffin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).