I was just wondering why my code does not register my CTRL+ Z input? When i input CTRL+ Z it does not exit the while loop somehow.
However when I substitute the scanf()
function with a getchar()
function, it suddenly works! could anyone out there help enlighten me on this?
#include <stdio.h>
#include <stdlib.h>
int main(){
char grade;
while( grade != EOF){
scanf("%c" , &grade);
switch(grade){
case 'a':
printf("you got an a!\n");
break;
case 'b':
printf("you got a b!\n");
break;
case'\n':
break;
default:
printf("error :(\n");
break;
}
}
printf("Hello world!\n");
return 0;
}