回复 80楼 TonyDeng
哦,那我百度一下fgetc的用法去
回复 80楼 TonyDeng
小哥,我又想到个问题,如果我突然打着字想退出,那不是按esc退出吗,但是这个怎么实现啊,esc键不是普通的字符啊???
#include<stdio.h> #include<time.h> #define Key_Esc 0x1b long t1,t2; int n; main() { int word(); int english(); int Class(); int c1(); int c2(); int c3(); int n; textcolor(0); textbackground(1); clrscr(); gotoxy(28,8); cprintf("dan zi lian xi an 1"); printf("\n"); gotoxy(28,10); cprintf("ying wen lian xi an 2"); printf("\n"); gotoxy(28,12); cprintf("wen zhang lian xi an 3"); printf("\n"); scanf("%d",&n); switch(n) { case Key_Esc:return 0; case 1:{clrscr();word();}break; case 2:{clrscr();english();}break; case 3:{clrscr();Class();};break; } getch(); } int word() { char a[20],b[20]; int i; t1=time(NULL); srand(time(NULL)); for(i=0;i<20;i++) { a[i]=97+rand()%26; printf("%c",a[i]); b[i]=getch(); if(b[i]==Key_Esc)return 0; if(a[i]==b[i]) { n++; printf("%c\n",b[i]); } else { textcolor(4); cprintf("%c",b[i]); printf("\n"); } } t2=time(NULL); printf("mei fen zhong da zi%d",60*n/((int) (t2-t1))); } int english() { char a[10][30],b[10][30]; int i,j,m; t1=time(NULL); srand(time(NULL)); for(j=0,i=1;j<10;j++,i+=2,gotoxy(1,i)) { for(m=0;m<30;m++) { a[j][m]=97+rand()%26; cprintf("%c",a[j][m]);} } gotoxy(1,2); for(j=0,i=1;j<10;j++,i+=2,gotoxy(1,i+1)) for(m=0;m<30;m++) { if((b[j][m]=getch())=='\n') { fflush(stdin);break; } else if(b[j][m]==Key_Esc) return 0; if(b[j][m]==a[j][m]) { n++; printf("%c",b[j][m]); } else { textcolor(4); cprintf("%c",b[j][m]); } } t2=time(NULL); printf("mei fen zhong da zi %d ge .",60*n/((int)(t2-t1))); } int Class() { int n; printf("1 A boy\n"); printf("2 lal\n"); printf("3 big head\n"); printf("qing xuan ze 1~3\n"); scanf("%d",&n); switch(n) { case Key_Esc:return 0; case 1:{clrscr();c1();}break; case 2:{clrscr();c2();}break; case 3:{clrscr();c3();}break; } } int c1() { FILE *fp; int a[200],b[200],i=0; fp=fopen("A BOY.txt","r"); while((a[i]=fgetc(fp))!=EOF) { printf("%c",a[i]); i++; } gotoxy(1,1); t1=time(NULL); for(i=0;i<200;i++) { b[i]=getch(); if(b[i]==Key_Esc)return 0; if(a[i]==b[i]) { textcolor(1); cprintf("%c",b[i]); } else { textcolor(4); cprintf("%c",a[i]); } } fclose(fp); t2=time(NULL); printf("mei fen zhong da zi%d",60*n/((int) (t2-t1))); } int c2() { FILE *fp; int a[500],b[500],i=0; fp=fopen("lal.txt","r"); while((a[i]=fgetc(fp))!=EOF) { printf("%c",a[i]); i++; } gotoxy(1,1); t1=time(NULL); for(i=0;i<500;i++) { b[i]=getch(); if(b[i]==Key_Esc)return 0; if(a[i]==b[i]) { textcolor(1); cprintf("%c",b[i]); } else { textcolor(4); cprintf("%c",a[i]); } } fclose(fp); t2=time(NULL); printf("mei fen zhong da zi%d",60*n/((int) (t2-t1))); } int c3() { FILE *fp; int a[300],b[300],i=0; fp=fopen("big head.txt","r"); while((a[i]=fgetc(fp))!=EOF) { printf("%c",a[i]); i++; } gotoxy(1,1); t1=time(NULL); for(i=0;i<300;i++) { b[i]=getch(); if(b[i]==Key_Esc)return 0; if(a[i]==b[i]) { textcolor(1); cprintf("%c",b[i]); } else { textcolor(4); cprintf("%c",a[i]); } } fclose(fp); t2=time(NULL); printf("mei fen zhong da zi%d",60*n/((int) (t2-t1))); }貌似实现了按ESC退出,就是输入后先扫描下键值,是ESC就退出