打字测速程序
打字程序主要是让选择的文本内容隔行显示,关键是要在空行的区域输入文字,这个怎么实现?各位大侠不吝赐教一下
C/C++的代码
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
int main()
{
FILE* fp;
long t, fpos, maxpos;
double start,finish;
char buf_out[100];
char ch_ans = 'Y';
int ch_file,i,count;
fp = fopen("1.txt", "r");
fseek(fp, SEEK_SET,SEEK_END);
maxpos = ftell(fp);
while(ch_ans != 'n')
{
count = i = 0;
srand((unsigned)time(&t));
fpos = rand()%maxpos;
fseek(fp,fpos,SEEK_SET);
while((ftell(fp)<maxpos)&&(ch_file=fgetc(fp)!= ' '))
;
if(ftell(fp) == maxpos)
fseek(fp, 0, SEEK_SET);
fscanf(fp,"%s ", buf_out);
printf("output:%s\ninput: ", buf_out);
fflush(stdin);
start = (double)clock();
while(((ch_ans=getchar()) != ' ') && ch_ans != '\n')
{
if((buf_out[i] != '/0') && buf_out[i++] == ch_ans)
count ++;
}
finish = (double)clock();
printf("correct: %d time used: %4.2fms\ntest again?(y/n) ",count,finish-start);
fflush(stdin);
ch_ans = getchar();
}
fclose(fp);
return 0;
}