C语言 “未定义对 clrscr() 的引用;”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21750450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:45:40  来源:igfitidea点击:

"UNDEFINED REFRENCE TO clrscr();"

c

提问by Samuel

#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,a,b,c,choice;
do
{
    printf("enter any two numbers\n");
    scanf("%d%d",&a,&b);
    printf("pressing one add the two numbers\nenter one if you want to\n");
    scanf("%d",&choice);
    switch(choice)
    {
        case 1:
            {
                c=a+b;
                printf("the sum of the entered numbers%.1f\n\n:",c);
                break;
            }
        default:
            printf("you have entered an invalid");
            break;
    }
    clrscr();
}
while(i==1);
getch();
}

i do not know cause my classmate is using turbo c and it's fine,for me i am using dev c++ but looks like clrscr(); is not known to the compiler help please.

我不知道因为我的同学正在使用 turbo c,这很好,对我来说我使用的是 dev c++,但看起来像 clrscr();不知道编译器帮助。

回答by Ferenc Deak

Your classmate is programming under DOS, obviously you don't ... conio.hcomes with Turbo C and DOS ... So, remove the lines

你的同学在DOS下编程,显然你没有......conio.h带有Turbo C和DOS......所以,删除这些行

#include<conio.h>

and

clrscr();

and

getch();

to make your program compile ...

使您的程序编译...

... and do not use %.1fto print an int.

... 并且不要%.1f用于打印 int。

... and main()must return int

...并且main()必须返回int

* and do not copy from your classmate ... he seems to be stuck in the stone age*

*不要抄袭你的同学...他似乎被困在石器时代*

回答by Sadique

From Wiki:

来自维基

conio.h is a C header file used mostly by MS-DOS compilers to provide console input/output.1It is not part of the C standard library, ISO C nor is it defined by POSIX

Member functions

kbhit - Determines if a keyboard key was pressed.
getch - Reads a character directly from the console without buffer, and without echo.
getche - Reads a character directly from the console without buffer, but with echo.
ungetch - Puts the character c back into the keyboard buffers.
cgets - Reads a string directly from the console.
cscanf - Reads formatted values directly from the console.
putch - Writes a character directly to the console.
cputs - Writes a string directly to the console.
cprintf - Formats values and writes them directly to the console.
clrscr - Clears the screen.

Compilers provided later than 1989 have prepended an _ to the names, to comply with the requisites of the ANSI C Standard.

conio.h 是一个 C 头文件,主要由 MS-DOS 编译器用来提供控制台输入/输出。1它不是 C 标准库、ISO C 的一部分,也不是由 POSIX 定义的

成员函数

kbhit - Determines if a keyboard key was pressed.
getch - Reads a character directly from the console without buffer, and without echo.
getche - Reads a character directly from the console without buffer, but with echo.
ungetch - Puts the character c back into the keyboard buffers.
cgets - Reads a string directly from the console.
cscanf - Reads formatted values directly from the console.
putch - Writes a character directly to the console.
cputs - Writes a string directly to the console.
cprintf - Formats values and writes them directly to the console.
clrscr - Clears the screen.

1989 年以后提供的编译器在名称前加了一个 _,以符合 ANSI C 标准的要求。

conio.his not part of the C standard. It is a Borland extension, and works only with Borland compilers (and perhaps some other commercial compilers). Dev-C++ uses GCC, the GNU Compiler Collection, as it's compiler. GCC is originally a UNIX compiler, and aims for portability and standards-compliance.

conio.h不是 C 标准的一部分。它是 Borland 扩展,仅适用于 Borland 编译器(可能还有一些其他商业编译器)。Dev-C++ 使用 GCC,即 GNU 编译器集合,因为它是编译器。GCC 最初是一个 UNIX 编译器,旨在实现可移植性和符合标准。

You can use Borland functions this way in Dev C++: Include conio.h to your source, and add C:\Dev-C++\Lib\conio.o to "Linker Options" in Project Options (where C:\Dev-C++ is where you installed Dev-C++).

您可以在 Dev C++ 中以这种方式使用 Borland 函数:将 conio.h 添加到您的源代码中,并将 C:\Dev-C++\Lib\conio.o 添加到项目选项中的“链接器选项”(其中 C:\Dev-C++ 是安装 Dev-C++ 的地方)。