#include <stdio.h>
int main(){
char ch;
while((ch=getchar())!=EOF){
putchar(ch);
}
char ch2 = 'A';
printf("ch2=======>%c\n",ch2);
ch2 = getchar();
printf("ch2=======>%d\n",ch2);
return 0;
}
I don't understand why it skips the ch2=getchar()
input, and I get ch2 == -1 which is the value of EOF. I tried to solve this by adding another getchar()
before ch2=getchar()
, but I still get ch2 == -1. Why is it and how to fix it? Thanks for helping.
I'm using MacOS.