A
arnuld
/* K&R@, 1.5.1 - File Copying */
#include<stdio.h>
int main()
{
int c;
while((c = getchar())!= EOF)
putchar(c);
return 0;
}
--------- OUTPUT -----------
[arch@voodo kr2]$ gcc -ansi -pedantic -Wall -Wextra 1.5.1_file-
copying.c
[arch@voodo kr2]$ ./a.out
like this
like this
and thia
and thia
[arch@voodo kr2]$
you can see that "putchar" prints something only after hitting the
newline. this is exactly in agreement with what K&R2 says at the
beginning of section 1.5:
"Text input or output, regardless of where it originates or where it
goes to, is dealt with as streams of characters. A text stream is a
sequence of characters divided into lines; each line consists of zero
or more characters followed by a newline character"
whereas at the beginning of section 1.5.1 K&R2 says:
"The simplest example is a program that copies its input to its output
one character at a time"
these statements are exactly opposite to each other. i am confused
about this. looking at the code conforms that we are printing only one
character at a time whereas running the code shows that it is printing
a line at a time, rather than one character at a time. how does it
work ?
#include<stdio.h>
int main()
{
int c;
while((c = getchar())!= EOF)
putchar(c);
return 0;
}
--------- OUTPUT -----------
[arch@voodo kr2]$ gcc -ansi -pedantic -Wall -Wextra 1.5.1_file-
copying.c
[arch@voodo kr2]$ ./a.out
like this
like this
and thia
and thia
[arch@voodo kr2]$
you can see that "putchar" prints something only after hitting the
newline. this is exactly in agreement with what K&R2 says at the
beginning of section 1.5:
"Text input or output, regardless of where it originates or where it
goes to, is dealt with as streams of characters. A text stream is a
sequence of characters divided into lines; each line consists of zero
or more characters followed by a newline character"
whereas at the beginning of section 1.5.1 K&R2 says:
"The simplest example is a program that copies its input to its output
one character at a time"
these statements are exactly opposite to each other. i am confused
about this. looking at the code conforms that we are printing only one
character at a time whereas running the code shows that it is printing
a line at a time, rather than one character at a time. how does it
work ?