Can someone enligten me on what below program does?
I understand getchar and putchar.. but what is this program suppose to do?
I try to put printf on it, but it shows nothing..
can someone explain to me what this program is suppose to do?
It is reading something and assigning to c?
so, if I do, ./a.out filename , will it assign entire filename's content into c?
#include <stdio.h>
/* copy input to output; 1st version */
main()
{
int c;
c = getchar\(\);
while \(c != EOF\) \{
putchar\(c\);
c = getchar\(\);
\}
Hi,
The program basiaclly copies the character entered by the user to the variable c and then rits it to the output.
This goes on until the user enters the EOF character(I am not sure abt the character)
n[root@rleeserver programming_language_c]# cat > yahoo
hi
how are you
[root@rleeserver programming_language_c]# ./file_copy <yahoo
h105
ni32
n 10
n
104
nh111
no119
nw32
n 97
na114
nr101
ne32
n 121
ny111
no117
nu10
n
-1
between below program that spits out 0 for EOF and /usr/include/stdio.h, which has , I am bit confused. I ran below program and I do get 0 for EOF..
can someone please help bit further..
/* End of file character.
Some things throughout the library rely on this being -1. */ #ifndef EOF
# define EOF (-1) #endif
/* This program prompts for input, and then captures a character
from the keyboard. If EOF is signalled (typically through a
control-D or control-Z character, though not necessarily),
the program prints 0. Otherwise, it prints 1.
*
If your input stream is buffered (and it probably is), then
you will need to press the ENTER key before the program will
respond.
*/
#include <stdio.h>
int main(void)
{
printf("Press a key. ENTER would be nice :-)\n\n");
printf("The expression getchar() != EOF evaluates to %d\n", getchar() != EOF);
return 0;
}
8 bit characters are between 0 and 255. EOF has to be outside that range, hence why getchar and fgetc return an int and not a char. If you read that into a char it will work (a) if char is naturally signed (b) character 255 does not appear in the data stream.