Answer is not easy, answer useful please adopt, click on the right side of the answer to adopt! The
error is caused by you comparing characters to strings("EOF").(ch = getchar())! = EOF. EOF is a special constant that represents the end of a file. It is a macro definition, usually -1, in < stdio.h> Is defined in. You have an extra close parenthesis in the while statement that needs to be removed or it will compile incorrectly.
while ((ch = getchar()) != EOF)
Modified code:
#include
#include
int main(int argc, char const *argv[])
{
int ch;
while ((ch = getchar()) != EOF)
{
putchar(ch);
}
system("pause");
return 0;
}
modified the EOF and removed the extra closing parenthesis and should compile and run properly. This code reads the input all the way to the end of the file(EOF) and outputs the read characters to the screen.
Where the phrase system("pause") stops the console window closing on windows, delete this sentence if you are running on another system.