Run command sequence:
gcc -Wall main.c -o a.out
./a.out < inputfile.txt
I want to read from file like ./a.out < inputfile.txt
and after iterating char by char, print OK if all the characters are alphanumeric or ERROR otherwise. I can't seem to get this to work.
inputfile.txt
the brown fox jumped over the dog
this is another string
here is another string
main.c
int main() {
char c;
while (!feof(stdin)) {
c = getchar();
if (!isalnum(c)) {
printf("ERROR!\n");
exit(1);
}
}
printf("OK\n);
return 0;
}