I am new to programming, and getchar() or EOF in specific. I was testing an example in K&R which used EOF as the termination condition.
#include <stdio.h>
#define EOF 'A'
int main(){
int c, i, nwhite, nother, ndigit[10];
nwhite = nother =0;
for(i = 0; i < 10; i++){
ndigit[i] = 0;
}
while((c = getchar()) != EOF){
switch(c){
case '0' : case '1' : case '2' : case '3' : case '4' : case '5' :
case '6' : case '7' : case '8' : case '9' :
ndigit[c - '0']++;
break;
case ' ' : case '\n' : case '\t' :
nwhite++;
break;
default :
nother++;
break;
}
}
printf("digits =");
for(i = 0; i < 10; i++){
printf(" %d", ndigit[i]);
}
printf(", white spaces = %d, other = %d\n", nwhite, nother);
return 0;
}
But I am unable to input EOF in vscode Windows. I have already tried [Ctrl+D], [Ctrl+Z] and other suggested answers elsewhere.
When I define EOF to something like 'A', it puts a warning of redefinition but the program works exactly as intended.
The warning says about the default stdio.h value #define EOF (-1)
, and I have inputted (-1) also but still doesn't work