amankhan
asked on
What is the difference between this n this code ..
What is the difference between this
int main()
{
char c;
while ( (c = getchar()) != EOF ) ----------Line 1
putchar(c); ------------- Line 2
return 0;
}
and this
int main()
{
char c;
while ( (c = getchar()) != EOF ) ----------Line 1
return 0;
}
int main()
{
char c;
while ( (c = getchar()) != EOF ) ----------Line 1
putchar(c); ------------- Line 2
return 0;
}
and this
int main()
{
char c;
while ( (c = getchar()) != EOF ) ----------Line 1
return 0;
}
In the first case, each of the characters given as input is echoed back. This doesnt happen in the second case.
Eg:
If you type "abc", you will get "aabbcc" in the first case, and just "abc" in the second case.
Eg:
If you type "abc", you will get "aabbcc" in the first case, and just "abc" in the second case.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
\n is a better option to using EOF if the intention is to get a single line from standard input.
EOF is used to while getting input from files.
EOF is used to while getting input from files.
EOF can be supplied from stdin too ... ctrl D
>> EOF can be supplied from stdin too ... ctrl D
Oh, didn't know that. Is this true on DOS/Windows too?
Oh, didn't know that. Is this true on DOS/Windows too?
I guess it is .. not sure though, not really a windows/dos programmer
first code wll print all the character it reads ... and then return
second code will read only one char and return without printing anything
Sunnycoder