Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
12
返回列表 发新帖
楼主: shetaikeng
打印 上一主题 下一主题

求救C language

[复制链接]

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

11#
发表于 2009-8-2 10:19 PM |只看该作者
原帖由 shetaikeng 于 2009-8-2 09:52 PM 发表
那请问要如何更改???
我也不知道要如何declare variables



那麼可否問一下, 到目前為止以下這部分是你本身寫的嗎?? 要是真的是你寫的那麼應該知道甚麼是 declaration


    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #define ESC 27
    #define u 117
    #define d 100
   
    void UPP();
    void DOWN();
    int ChangeTime(int);
    //creating a GLOBAL integer array of 10 elements
   
    int numArray[]={1,2,3,4,5,6,7,8,9,10};
    int time=1;
    char key;
    int index;
    int temp;
   
    int main()
    {
   
        do
        {     
              system("cls");
              //display the outlook
              printf("\tUp/Down Number Rotation\n");
              printf("\t=========================\n\n");
              printf("\tEnter [U] for up rotation\n");
              printf("\tEnter [D] for down rotation\n");
              printf("\tTo stop rotation, any key except [U],[D],[ESC]\n\tPress ESC to quit at anytime.\n\n");
              printf("\tHit any key to start\n\n\t");
              key=getch();
              do
              {
                  for (index=0; index<10; index++)//rotate
                  {
                      printf("%02d ",numArray[index]);
                      _sleep(time*100);                 
                     
                  }
                  printf("\tTime=0.%ds  -STOP KEY\n\t\a",time);
                  
                  if(kbhit())
                  {
                      key=getch();
                      while(key!=ESC)
                      {
                          switch(key)
                          {
                              case'u':UPP();break;
                              case'd': DOWN();break;
                              case'1':ChangeTime(1);break;
                              case'2':ChangeTime(2);break;
                              case'3':ChangeTime(3);break;
                              case'4':ChangeTime(4);break;
                              case'6':ChangeTime(6);break;
                              case'7':ChangeTime(7);break;
                              case'8':ChangeTime(8);break;
                              case'9':ChangeTime(9);break;
                          }
                          if(key!=u && key!=d)//if neither "u" nor "d" is hit
                          {
                              break;//breaky the while loop to go back to STOP KEY mode
                          }
                      }     
                  }//end of kbhit()
              }while(key != ESC );//end of the rotation
              
              printf("Try again?");
              key=getch();
        }while(key!='n');//end of do-while loop
            
        printf("\n");
        system("pause");
        return 0;
    }
   
    void UPP()
    {
         while(key==u && key!=ESC && key!=d)
         {
             /* using for-loop to shift all 10 elements in one go */
             for(index=0; index<9; index++)
             {
                 temp = numArray[index+1];         // moving the element content pointed by index to a temporary location
                 numArray[index+1] = numArray[index];  // moving the next element contect to the element content pointed by index
                 numArray[index] = temp ;        // moving the element content pointed by index from the temporary location to the next element content pointed by index
             }
            
             for(index=0; index<10; index++)
             {
                 printf("%02d ",numArray[index]);
                 _sleep(time*100);
             }
             printf("\tTime=0.%ds  -UP KEY\n\t\a",time);
             if(kbhit())
             {
                 key=getch();
                 switch(key)
                 {
                     case'1':ChangeTime(1);break;
                     case'2':ChangeTime(2);break;
                     case'3':ChangeTime(3);break;
                     case'4':ChangeTime(4);break;
                     case'6':ChangeTime(6);break;
                     case'7':ChangeTime(7);break;
                     case'8':ChangeTime(8);break;
                     case'9':ChangeTime(9);break;
                 }
                 break;
                                             
             }// a key is detected again and it's not u
         }//end of upp key while loop
    }
   
    void DOWN()
    {
         while(key!=ESC && key!=u && key==d)
         {
             /* using for-loop to shift all 10 elements in one go */
             for(index=9; index>0; index--)
             {
                 temp = numArray[index];         // moving the element content pointed by index to a temporary location
                 numArray[index] = numArray[index-1];  // moving the next element contect to the element content pointed by index
                 numArray[index-1] = temp ;        // moving the element content pointed by index from the temporary location to the next element content pointed by index
             }
             for(index=0; index<10; index++)
             {
                 printf("%02d ",numArray[index]);
                 _sleep(time*100);
             }
             printf("\tTime=0.%ds  -DOWN KEY\n\t\a",time);
             if(kbhit())
             {
                key=getch();
                switch(key)
                 {
                     case'1':ChangeTime(1);break;
                     case'2':ChangeTime(2);break;
                     case'3':ChangeTime(3);break;
                     case'4':ChangeTime(4);break;
                     case'6':ChangeTime(6);break;
                     case'7':ChangeTime(7);break;
                     case'8':ChangeTime(8);break;
                     case'9':ChangeTime(9);break;
                 }
                break;
                 
             }// a key is detected again and it's not u
         }//end of upp key while loop
    }

int ChangeTime(int InputTime)
{
     time=InputTime;
}


回复

使用道具 举报

5

主题

0

好友

1733

积分

白银长老

Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9

12#
发表于 2009-8-3 10:46 PM |只看该作者

回复 #11 Super-Tomato 的帖子

算是自己写的吧
因为遇到问题是就问老师如何解救
但是因为要交了但是老师不在
所以只好上网求助


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

13#
发表于 2009-8-4 03:14 AM |只看该作者

回复 #12 shetaikeng 的帖子

decralarion == 应该就是指给一个代数吧。 像int xx = xx; 之类的东西。
应该是 function 内的东西无法拿出来共享。 所以就 undeclared 了咯。

你的code 是长到 。。。。。看了眼花

[ 本帖最后由 宅男-兜着走 于 2009-8-4 03:22 AM 编辑 ]


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

14#
发表于 2009-8-4 03:09 PM |只看该作者
原帖由 shetaikeng 于 2009-8-3 10:46 PM 发表
算是自己写的吧
因为遇到问题是就问老师如何解救
但是因为要交了但是老师不在
所以只好上网求助



有些時候不需要說到那麼白, 甚麼都要等待別人給你答案的話, 我想你以後會很難在社會生存
http://www.google.com.my/search? ... ;btnG=Google+Search


回复

使用道具 举报

0

主题

0

好友

5

积分

入门会员

15#
发表于 2009-8-12 05:19 PM |只看该作者
declare 是让complier预留记忆空间给变数是吗?


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

16#
发表于 2009-8-13 12:48 AM |只看该作者
原帖由 goolias 于 2009-8-12 05:19 PM 发表
declare 是让complier预留记忆空间给变数是吗?


嗯, 沒錯, 一般嚴謹的程式語言都會要求先進行宣告


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

17#
发表于 2009-8-13 11:56 PM |只看该作者
也是为了方便你追踪,debug 和 减少昆乱的 方法


回复

使用道具 举报

0

主题

0

好友

883

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

18#
发表于 2009-8-14 12:04 AM |只看该作者

回复 #1 shetaikeng 的帖子

楼主的code很长em0011  
我以后也不敢写那么长  因我时常被指点make a simplify program


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

19#
发表于 2009-8-14 12:10 AM |只看该作者
我有个 30k 行的逻辑层


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-26 06:25 PM , Processed in 0.114527 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部