| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 479 人关注过本帖
标题:哪里错了?
只看楼主 加入收藏
卢露露
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2011-9-13
结帖率:75%
收藏
已结贴  问题点数:10 回复次数:7 
哪里错了?
#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>>>>>>>>>>>");
}

搜索更多相关主题的帖子: include double speed start 
2011-09-13 15:25
statics
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:163
专家分:625
注 册:2011-8-29
收藏
得分:3 
什么错?

惟我独行...
2011-09-13 16:42
卢露露
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2011-9-13
收藏
得分:0 
回复 2楼 statics
运行时 好像前面的公共函数库不对劲
2011-09-13 16:45
scott_dw
Rank: 2
等 级:论坛游民
帖 子:35
专家分:52
注 册:2011-8-30
收藏
得分:3 
<graphics.h> 是TC里面的图形库,如果要用的话应该用TC来编译,VC++有他自己的另外图形库、、



我不懂,帮你在baidu 上查了查

你没有自己编写那个库吧
2011-09-13 18:47
卢露露
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2011-9-13
收藏
得分:0 
回复 4楼 scott_dw
没有 我还不懂呢 嘿嘿
2011-09-13 23:43
冰颜
Rank: 1
等 级:新手上路
帖 子:5
专家分:3
注 册:2011-9-14
收藏
得分:3 
露 你的程序好长~我都看不懂
2011-09-14 16:13
zs帅
Rank: 1
等 级:新手上路
帖 子:6
专家分:7
注 册:2011-9-18
收藏
得分:0 
你个破露露,骗我是吧,弄一个全部都是错误的代码叫我帮你改,与你上面的一点都不一样,我恨你!!!
2011-09-18 11:13
zs帅
Rank: 1
等 级:新手上路
帖 子:6
专家分:7
注 册:2011-9-18
收藏
得分:0 
  dew
2011-09-18 11:15
快速回复:哪里错了?
数据加载中...
 
   



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

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