linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shriramana Sharma <samjnaa@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Help: need to prevent infinite loop
Date: Tue, 17 Jan 2006 10:06:36 +0530	[thread overview]
Message-ID: <200601171006.36978.samjnaa@gmail.com> (raw)

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

             reply	other threads:[~2006-01-17  4:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-17  4:36 Shriramana Sharma [this message]
2006-01-17  7:14 ` Help: need to prevent infinite loop 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200601171006.36978.samjnaa@gmail.com \
    --to=samjnaa@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).