For some reason my scanf function will not work properly. The first scanf works, if i hit 'a' it will go to that case, same thing for 'd' and 'q'.
I enter 'a' to go to the first case, but no matter what i enter into that scanf function it skips down to the else and says 256 is not a valid entry.....
What is wrong, someone pls help me.
It is probly something stupid so forgive me cuz im new to this...
I tried replacing scanf with getchar, the first one would work fine, but the second one would get skiped over????????
Maybe i should use a different function?
Thanks for you time and help pplCode:#include <stdio.h> main () { int s1, s2, name, number; clrscr (); printf (" MAIN MENU \n\n"); printf ("[A]dd Records\n"); printf ("[D]isplay Records\n"); printf ("[Q]uit Program\n\n"); printf ("Selection: "); scanf("%c", &s1); //the first scanf switch (s1) { case 'a': clrscr (); printf (" ADD RECORDS \n\n"); printf ("Enter [N]ame\n"); printf ("Enter [P]hone Number\n"); printf ("[R]eturn To Main Menu\n\n"); printf ("Selection: "); scanf ("%c", &s2); //the second scanf, the one that doesn't work if (s2 == 'n') { clrscr (); printf (" ADD NAME \n\n"); printf ("Enter Name <Lastname, Firstname>: "); } if (s2 == 'p') { clrscr (); printf (" ADD PHONE NUMBER \n\n"); } if (s2 == 'r') { clrscr (); } else { clrscr (); printf ("%c Is Not A Valid Entry, Please Select Again\n", s2); printf ("Selection: "); } case 'd': printf (" DISPLAY RECORDS \n\n"); break; case 'q': clrscr (); printf ("Thank You, BYE\n\n"); break; default: clrscr (); printf ("%c Is Not A Valid Entry, Please Select Again\n", s1); printf ("Selection: "); break; } return 0; }



LinkBack URL
About LinkBacks


