u.user
February 7th, 2010, 01:12 PM
Hello all.
I was running this simple C code in ubuntu 9.10
#include <stdio.h>
int main(void){
char c;
while((c=getchar())!=EOF)
putchar(c);
return 0;
}
When I input a word, like test for exmple and press CTRL-D, it gets automatically outputed like
(what happens in console, italic is the output)
$./test
test<CTRL+D>test
123<ENTER>
123
<CTRL+D>
PROGRAM EXITS
My question is, knowing that getchar() uses buffer, meaning, all what is input will be available to it after pressing ENTER, why is it that when i type test<CTRL+D> without pressing enter i get test as output and i can continue inputting... so what is CTRL+D doing here? Also when i just press CTRL+D when there is no input before it, it is exitting. Can someone please explain what is happening?
Thank you
I was running this simple C code in ubuntu 9.10
#include <stdio.h>
int main(void){
char c;
while((c=getchar())!=EOF)
putchar(c);
return 0;
}
When I input a word, like test for exmple and press CTRL-D, it gets automatically outputed like
(what happens in console, italic is the output)
$./test
test<CTRL+D>test
123<ENTER>
123
<CTRL+D>
PROGRAM EXITS
My question is, knowing that getchar() uses buffer, meaning, all what is input will be available to it after pressing ENTER, why is it that when i type test<CTRL+D> without pressing enter i get test as output and i can continue inputting... so what is CTRL+D doing here? Also when i just press CTRL+D when there is no input before it, it is exitting. Can someone please explain what is happening?
Thank you