c - Instruction executes twice -


i have following piece of code. want user enter a or r , continue executing program, or try user input if enters else.

but problem is, when enter illegal value program shows message twice, , not once. how can make message ever show once?

label:      puts ("a/r?");      c = getchar ();      if (c != 'a' || c != 'r')        goto label;  

if user enters a, have press enter key on keyboard input register. key leaves newline character in standard input , therefore character read second time around , test fails again.

the test fails input because trying have input 2 things @ same time. have use && instead of || in order check if input either 1 of characters looking for. know sounds should other way around, not case have observed.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -