www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/06/01:28:48

From: jkeene AT unlinfo DOT unl DOT edu (Jon Keene)
Subject: What stupid error am I making?
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Fri, 5 May 1995 23:11:53 -0500 (CDT)

What's wrong with the fragment below?  I've tried it this way, which
results in the menu printing twice on incorrect input, and with option
as an int, which results in an infinite loop when the input character
isn't 0 or 1.  scanf _is_ supposed to ignore '\n' in the input,
isn't it?

Thanks,
Jon

	char option;

 	do {
 		printf("\n   Choose one of the following: ");
 		printf("\n   0 = end program");
 		printf("\n   1 = test me\n");
 		printf("\n   Enter option: ");
 		scanf("%c", &option);
 	} while (option != '0' && option != '1');
 
-- 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019