Getchar() Problems


i using c, , tried code user decide do:

code:
while (choice!='a'&&choice!='b'&&choice!='c') {  		printf("please enter option 1, b option 2, or c option 3.\n");  		choice=getchar();  		printf("\b");  	}
but when type, say, d in, program supposed ask again, instead, asks twice. that's why add \b, doesn't help. also, when type multiple letters, end asking choose option lot more.

so, how fix this? part of code accepts anything, ends getting input last question.
 

in posted code, you're not accounting fact you're pressing 'd' key followed return or enter key. that's 2 key presses, 2 characters input.

if print decimal (or hex or octal) number of value of choice, should better understanding of what's happening.

trying printf() backspace nothing useful. backspace output formatting character. has no effect on what's being read input.
 


Forums Macs Mac Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

Mac OS X Server as File Server for 50/50 Mac & PC Workgroup

Permissions Problem?

iPhone won't sync with iTunes