0
Follow
0
View

I encountered a compilation problem while learning c language

diaowanglu 注册会员
2023-01-25 19:05

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.

dwj313 注册会员
2023-01-25 19:05

Remove the close parenthesis after EOF in line 6.

#include"stdio.h"
#include"stdlib.h"
int main(int argc, char const *argv[])
{
    int ch;
    while ((ch = getchar()) != EOF)
    {
        putchar(ch);
    }
    system("pause");
    return 0;
}

img

About the Author

Question Info

Publish Time
2023-01-25 19:05
Update Time
2023-01-25 19:05