哪里错了?
#include "stdio.h"#include "conio.h" /*用于设置字符颜色的头文件*/
#include "stdlib.h"
#include "string.h"
#include "dos.h" /*用于计算时间的头文件*/
#include "graphics.h" /*用于设置屏幕背景头文件*/
int rownum=0,right; /*全局变量*/
int *rightptr=&right;
double speed,*speedptr=&speed;
char str[100][100];
void main()
{ int len;
char key;
textbackground(9); /*设置背景颜色为浅蓝色*/
start(); /*显示开始界面的函数*/
getch();
do /*函数循环使用*/
{
clrscr(); /*清屏*/
printf("the textlist you can choose:\n");
printf("text1---high school student \n");
printf("text2---use time wisely\n");
printf("text3---hhh\n");
len=select(str);
deal(str,len,&right,&speed); /*该函数完成打字过程,并计算出速度和正确率*/
clrscr();
textbackground(0); /*设置背景颜色为黑色*/
clrscr();
end(len,right,speed); /*输出结果的函数*/
gotoxy(20,13);
printf("Do you want continue?(y or n):");
key=getch();
}while(key=='Y' || key=='y');
}
int start() /*显示初始页面*/
{ gotoxy(3,4);
printf("-----------------------------------------------------------------------------\n");
gotoxy(3,6);
printf(" Welcome to practice \n");
gotoxy(3,8);
printf(" Designed by Huang \n");
gotoxy(3,10);
printf(" Date:2010-12-28 \n");
gotoxy(3,12);
printf("-----------------------------------------------------------------------------\n");
}
int select(char str[][100]) /*选择练习文章*/
{ FILE *fp;
int len=0;
int i=0;
char s;
do
{s=getch();
switch(s)
{
case '1': /*输入1选择第一篇文章*/
clrscr();
if((fp=fopen("F:\\text1.txt","r"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
while(fgets(str+i,80,fp)!=NULL) /*从文章中依次把79个字符存入str+i中*/
{
textcolor(14);
cprintf("%s",str+i); /*显示字符数组*/
printf("\n\n");
len=strlen(str+i)+len; /*计算出字符的个数*/
i++; /*得到显示在屏幕上的行数*/
}
rownum=i;
fclose(fp);
break;
case '2': /*输入2选择第二篇文章*/
clrscr();
if((fp=fopen("F:\\text2.txt","r"))==NULL)
{
printf("can't open file!\n");
exit(0);
}
while(fgets(str+i,80,fp)!=NULL)
{
textcolor(14);
cprintf("%s",str+i);
printf("\n\n");
len=strlen(str+i)+len;
i++;
}
rownum=i;
fclose(fp);
break;
case '3':
clrscr();
if((fp=fopen("F:\\text3.txt","r"))==NULL) /*输入3选择第三篇文章*/
{
printf("can't open file!\n");
exit(0);
}
while(fgets(str+i,80,fp)!=NULL)
{
textcolor(14);
cprintf("%s",str+i);
printf("\n\n");
len=strlen(str+i)+len;
i++;
}
rownum=i;
fclose(fp);
break;
}
}while(s!='1'&&s!='2'&&s!='3');
return(len);
}
int deal(char str[][100],int len,int *rightptr,double *speedptr) /*函数完成打字*/
{
struct time t1,t2;
double ti; /*时间差*/
int right=0;
int o=2; /*定义光标的行数*/
int u=0; /*u为输入字符的个数*/
int m,n;
char ch;
gettime(&t1); /*输入开始时的时间*/
gotoxy(1,2);
for (m=0;m<rownum;m++) /*控制输入的行数和列数*/
{
for (n=0;n<79;n++)
{
ch=getch();
u++;
if (ch==str[m][n]) /*对打入的字符进行对照,正确的输入原字符,错误的输入*,并计算出正确的个数*/
{
textcolor(14);
cprintf("%c",ch);
right++;
}
else
cprintf("*");
if(u==len) /*u等于len时,则停止循环*/
break;
}
o=o+2;
gotoxy(1,o);
}
gettime(&t2); /*输入结束时的时间*/
ti=(double)((t2.ti_hour*3600+t2.ti_min*60+t2.ti_sec)-(t1.ti_hour*3600+t1.ti_min*60+t1.ti_sec)); /*计算整个打字过程所用的时间*/
*rightptr=right;
*speedptr=((double)len /(double)ti)*60; /*计算打字速度*/
printf("\npress enter to end");
getchar();
}
int end(int len,int right,double speed) /*函数显示结果*/
{
gotoxy(20,5);
textcolor(12);
cprintf("<<<<<<<<<<<the result>>>>>>>>>>>");
gotoxy(20,7);
cprintf(" the right points is %lf% ",(double)right/len*100); /*显示正确率*/
gotoxy(20,9);
cprintf(" the speed is %lf c/m",speed); /*显示打字速度*/
gotoxy(20,11);
cprintf("<<<<<<<<<<<the result>>>>>>>>>>>");
}