windows 的正确 ansi c 示例是什么?
What is the proper ansi c example for windows?
有些书声称他们使用 ansi c 并使用 turbo c 编译器 运行 这些示例。我试图在 linux 上 运行 这些,但我发现这些示例仅适用于 windows。
#include<stdio.h>
#include<conio.h>
/* #include<dos.h> */
int main()
{
int a;
clrscr();
scanf("%d", &a);
printf("%d",a);
getch();
return 0;
}
我可以调用上面的例子ansi c吗?为什么或为什么不?
正如@milevyo 所说,这些功能是由Borland 的编译器实现的。在 Windows 上,您可以将 clrscr()
替换为 system("cls")
,将 getch();
替换为 _getch();
,或者更好的是 getchar()
.
conio.h
文件目录只有Borland C
支持。您可以使用getchar()
代替getch()
。
如果您无论如何都必须使用 getch()
,那么您可以使用 curses.h
文件而不是 conio.h
。它提供了 conio.h
和 getch()
的大部分功能。
如果您没有安装 curses.h
目录,那么您可以从 here
下载
#include <stdio.h>
#include <ncurses.h>
int main()
{
initscr(); /* start the curses mode */
int a;
scanf("%d", &a);
printf("%d",a);
getch();
endwin();
return 0;
}
有些书声称他们使用 ansi c 并使用 turbo c 编译器 运行 这些示例。我试图在 linux 上 运行 这些,但我发现这些示例仅适用于 windows。
#include<stdio.h>
#include<conio.h>
/* #include<dos.h> */
int main()
{
int a;
clrscr();
scanf("%d", &a);
printf("%d",a);
getch();
return 0;
}
我可以调用上面的例子ansi c吗?为什么或为什么不?
正如@milevyo 所说,这些功能是由Borland 的编译器实现的。在 Windows 上,您可以将 clrscr()
替换为 system("cls")
,将 getch();
替换为 _getch();
,或者更好的是 getchar()
.
conio.h
文件目录只有Borland C
支持。您可以使用getchar()
代替getch()
。
如果您无论如何都必须使用 getch()
,那么您可以使用 curses.h
文件而不是 conio.h
。它提供了 conio.h
和 getch()
的大部分功能。
如果您没有安装 curses.h
目录,那么您可以从 here
#include <stdio.h>
#include <ncurses.h>
int main()
{
initscr(); /* start the curses mode */
int a;
scanf("%d", &a);
printf("%d",a);
getch();
endwin();
return 0;
}