getch与getchar基本功能相同,差别是getch直接从键盘获取键值,不等待用户按回车,只要用户按一个键,getch就立刻返回,getch返回值是用户输入的ASCII码,出错返回-1输入的字符不会回显在屏幕上getch函数常用于程序调试中,在调试时,在关键位置显示有关的结果以待查看,然后用getch函数暂停程序运行,当按任意键后程序继续运行本题一个完美的程序如下,程序已在tc20和win-tc下运行通过。
说明:如果程序不能运行,请将initgraph(&gdriver,&gmode,"")函数中的""更改为你的TC安装目录。比如你的TC安装目录为D盘的Tools子目录下的TC目录,那么上述语句改为:initgraph(&gdriver,&gmode,"D:\\Tools\\TC");
同时保证在D:\\Tools\\TC目录里有文件EGAVGABGI,如果没有从TC安装目录下复制一个过来。万一不行,将本程序复制到你的TC安装目录下再运行。
如还有疑问,给我消息。
#include <stdioh>
#include <stdlibh>
#include <conioh>
#include <timeh>
#include <dosh>
#include <graphicsh>
int main()
{int i,j;
int gdriver=DETECT,gmode;
initgraph(&gdriver,gmode,"");
srand((unsigned)time(NULL));
setbkcolor(0);/ 如果背景色要改为蓝色,改为setbkcolor(BLUE),颜色要大写或用数字0-15 /
setlinestyle(0,0,3);
while(!kbhit()) / 按任一键退出此程序 /
{setcolor(rand()%16);
line(200,200,200,225);
delay(100000);
line(225,175,225,225);
delay(100000);
line(275,175,250,225);
delay(100000);
line(263,200,300,200);
delay(100000);
line(263,200,275,225);
delay(100000);
line(250,225,200,275);
delay(100000);
line(250,225,300,275);
delay(100000);
line(225,250,275,250);
delay(100000);
line(225,275,275,275);
delay(100000);
line(250,250,250,325);
delay(100000);
line(230,280,250,325);
delay(100000);
line(270,280,250,325);
delay(100000);
line(200,325,300,325);
delay(100000);
for(j=0;j<10;j++)
delay(300000);
cleardevice();
}
getch();
closegraph();
return 0;
}
用一小段代码,把其中的非中文字符过滤掉:
#include<stdioh>
int main()
{int i,j;
char s[100]="abcd1234原来中2345英6967文输dfdh入27现在只剩BBB中文824";
puts(s);
for(i=j=0;s[i];i++)
if(s[i]<0)s[j++]=s[i];
s[j]=0;
puts(s);
getch();
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)