| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 569 人关注过本帖
标题:求各位大虾大神这个程序哪里有问题?
只看楼主 加入收藏
宇智波
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-12-5
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:7 
求各位大虾大神这个程序哪里有问题?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>

int main()
{   
   FILE   *fp;
   char   ch,select[100];
   char   typed_text[500];
   char   str[100];
   int    totallength,typedlength;
   int    correctnum=0;
   int    i=0,n=0,j=0;
   char   number;
   long time1,  time2;
printf("************************************\n");
printf("*  welcome to words typing system  *\n");
printf("*      choose 1~5                  *\n");
printf("************************************\n");

printf("************************************\n");
printf("Please input the order number of paper\n");
scanf("%c", &number);
switch(number)
{
   case'1':      strcpy(select, "E:\\document\\5_1.txt");break;
   case'2':      strcpy(select, "E:\\document\\5_2.txt");break;
   case'3':      strcpy(select, "E:\\document\\5_3.txt");break;
   case'4':      strcpy(select, "E:\\document\\5_4.txt");break;
   case'5':      strcpy(select, "E:\\document\\5_5.txt");break;
   default:      printf("error option\n");break;
}


fp=fopen(select,"r+");
if(fp==NULL)
{printf("open error\n");exit(1);}


while((str[i]=fgetc(fp))!=EOF)
{ putchar(str[i]);
  i++;
}
printf("\n");
n=i;

printf("now start our game!\n");

time1=GetTickCount();


gets(typed_text);
for(j=0;j<n;j++)
{if(typed_text[j]==str[j])
 correctnum++;
}


time2=GetTickCount();
totallength=strlen(str);
typedlength=strlen(typed_text);



printf("Your accuracy is %.2f%%, and your speed is %d per minute!\n",correctnum*100/totallength,
(typedlength*1000*60)/(time2-time1));

printf("test\n");
return 0;
}

搜索更多相关主题的帖子: 大神 
2010-12-07 20:12
tfxanxing
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:82
专家分:165
注 册:2010-5-7
收藏
得分:0 
你应该说下你要做什么,程序有什么问题!
2010-12-07 23:09
宇智波
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-12-5
收藏
得分:0 
回复 2楼 tfxanxing
就是从文件中读出字符放入数组,用户输入字符放入数组,计算打字速度和正确率,可是执行到最后系统提示错误了tc停止工作,我不知道哪里出问题了?帮我看看好吗?
2010-12-08 09:16
xshy2051
Rank: 2
等 级:论坛游民
帖 子:27
专家分:33
注 册:2010-9-16
收藏
得分:0 
提示打开文件失败,不知道错哪里了…
2010-12-08 10:11
逐渐学习
Rank: 6Rank: 6
等 级:侠之大者
帖 子:113
专家分:454
注 册:2010-9-26
收藏
得分:5 
在gets(typed_text);之前增加
getchar();
gets(typed_text);

[ 本帖最后由 逐渐学习 于 2010-12-8 11:45 编辑 ]

帮人《---》帮己
2010-12-08 11:33
xiaomarn
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:348
专家分:2026
注 册:2009-3-18
收藏
得分:15 
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>

int main()
{  

   FILE   *fp;
   char   ch,select[100];
   //char   typed_text[500];
   char   str[100];
   int    totallength,typedlength;
   int    correctnum=0;
   int    i=0,n=0,j=0;
   char   number;
   unsigned long time1,  time2;
printf("************************************\n");
printf("*  welcome to words typing system  *\n");
printf("*      choose 1~5                  *\n");
printf("************************************\n");

printf("************************************\n");
printf("Please input the order number of paper\n");
scanf("%c", &number);
switch(number)
{
   case'1':      strcpy(select, "d:\\test1.txt");break;
   case'2':      strcpy(select, "E:\\document\\5_2.txt");break;
   case'3':      strcpy(select, "E:\\document\\5_3.txt");break;
   case'4':      strcpy(select, "E:\\document\\5_4.txt");break;
   case'5':      strcpy(select, "E:\\document\\5_5.txt");break;
   default:      printf("error option\n");break;
}


fp=fopen(select,"r+");
if(fp==NULL)
{printf("open error\n");exit(1);}


while((str[i]=fgetc(fp))!=EOF)
{ putchar(str[i]);
  i++;
}
printf("\n");
n=i;
//printf("%d ",n);
fclose(fp);
printf("now start our game!\n");

while((ch=getchar())!='\n')
    ;
time1=GetTickCount();
j=0;
while((ch=getchar())!=4)
{
    //printf("%d ",ch);
    if(ch==str[j])
        correctnum++;
    j++;
}
   


time2=GetTickCount();
totallength=strlen(str);
//printf("%d",totallength);
typedlength=j;



printf("Your accuracy is %.2f%%, and your speed is %f per minute!\n",(float)correctnum*100/n,
       (float)(typedlength*1000*60)/(time2-time1));

printf("test\n");
return 0;
}
ctrl+d结束输入
2010-12-08 12:53
ququguoguo
Rank: 2
等 级:论坛游民
帖 子:73
专家分:90
注 册:2010-10-20
收藏
得分:0 
我是来学习的
2010-12-08 13:22
a343637412
Rank: 7Rank: 7Rank: 7
来 自:そ ら
等 级:黑侠
帖 子:357
专家分:620
注 册:2010-9-26
收藏
得分:0 
不会....
2010-12-08 14:20
快速回复:求各位大虾大神这个程序哪里有问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025923 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved