EOF keyboard control
I am learning C in one of my classes and we are working on some basic programs like counting lines and characters of input and such. The problem i am running into is that when i press Ctrl + D to generate an EOF character, it does not work. For the program below, when i press Ctrl + D i get a '^D' printed in the terminal, but hte program does not end. I have to manually stop it with Ctrl+c.
======================
#include <stdio.h>
main() {
int c, n1;
n1 = 0;
while ((c == getchar()) != EOF) {
if (c == '\n') {
++n1;
}
}
printf("%d\n", n1);
}
======================
This program works in linux, but i'm not quite sure why it doesn't work on my mac. Is there a different key combination for an EOF?
Thanks,
--whit
MacBook Pro, Mac OS X (10.4.10)