it looks like you're mistaken about what stdin is.
in your example int the comments:
#include <stdio.h>
int main(void) {
int c; int i = 1;
printf("one\ntwo\nthree\n");
//while((c=fgetc(stdin)) != NULL) {
// comparing it with null is not correct here
// fgetc returns EOF when it encounters the end of the stream/file
// which is why an int is returned instead of a char
while((c=fgetc(stdin)) != EOF) {
if (c=='\n') {
printf("%d\n", i); i++;
}
}
return 0;
}
calling the program from the command line should output this
$ prog
one
two
three
you must send it a stream or a pipe to give it information through stdin
$ cat myfile | prog
one
two
three
4 # or however many lines are in myfile
stdin is blank by default. if you type into it, nothing is sent until you hi enter
this is what I see from compiling hte above code:
1 ./eof_testing
one
two
three
jfklksdf #my typing here
1
fjklsdflksjdf #mytyping here
2
fjklsdflksdfjf # my typing here
3
----- adding example of stty system call ----
#define STDIN_FD 0
#define STDOUT_FD 1
#define CHUNK_SIZE 8
#define QUIT_CHAR (char)4 /* C-D */
int main(){
write(STDOUT_FD,"hi\n",3);
char buff[CHUNK_SIZE];
int r, i;
system("stty -echo raw");
while(r = read(STDIN_FD, &buff, CHUNK_SIZE)){
for(i = 0; i < r; i++){
if(buff[i] == QUIT_CHAR)
goto exit;
}
write(STDOUT_FD, &buff, r);
}
exit:
system("stty echo cooked");
return 0;
}
now, however there is a whole new set of challenges to tackle, such as the key sends the '\r' character so instead of a newline it just returns to the start of the line. this is because now that the characters go directly to the program, lines are not terminated with the '\n' character which was happening in 'cooked' mode by the terminal.
http://starboard.firecrow.com/interface_dev/mle.git/editor/editor.c