scanf not working well in C -
if (a % 5) goto ask; else goto main; ask:printf("do want exit ? y \\ n . . . \n"); scanf("%c", &yn); getch(); if (yn == 'y') { y: system("cls"); yn = 1; goto sign; } else if (yn == 'y') goto y; else if (yn == 'n') { n: system("cls"); yn = 0; goto sign; } else if (yn == 'n') { goto n; } else { printf("sorry ..didn't catch ... "); goto ask; } someone me understand problem somereason output code "do u want exit y\n ?" getchar ... "sorry didnt catch u want exit y\n ? "
it looks jumped on scanf() first time , program went directly else ==> "sorry didnt that" , in second time fiugres out how use scanf().
scanf() reads characters %c , yes, enter key press [after previous input] pretty vaild %c [check below spoiler].
enter key press == newline
use
scanf(" %c", &yn); //mind space brefore `%c` ^ | to ignore previously-stored [also, leading] whitespace [including newline.]
note: eliminates need getch();
Comments
Post a Comment