| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 627 人关注过本帖
标题:請教一個程序,不知道為什麽編譯不過
只看楼主 加入收藏
wingyip
Rank: 1
等 级:新手上路
威 望:2
帖 子:119
专家分:0
注 册:2007-7-16
收藏
 问题点数:0 回复次数:0 
請教一個程序,不知道為什麽編譯不過
程序如下
#include<iostream>
#include<string>
using namespace std;

void setCode(char,int &pos,char &code[]);
//void setPause(char,int j,int &pause[]);
void printCode(char code[],int pause[],int len);

char chTree[32];

chTree[0]='';
chTree[1]='';
chTree[2]='T';
chTree[3]='E';
chTree[4]='M';
chTree[5]='N';
chTree[6]='A';
chTree[7]='I';
chTree[8]='O';
chTree[9]='G';
chTree[10]='K';
chTree[11]='D';
chTree[12]='W';
chTree[13]='R';
chTree[14]='U';
chTree[15]='S';
chTree[16]='?';
chTree[17]='';
chTree[18]='Q';
chTree[19]='Z';
chTree[20]='Y';
chTree[21]='C';
chTree[22]='X';
chTree[23]='B';
chTree[24]='J';
chTree[25]='P';
chTree[26]=',';
chTree[27]='L';
chTree[28]='_';
chTree[29]='F';
chTree[30]='V';
chTree[31]='H';

int main()
{
    int n,j,i,len,pos;
    string temp;
    int pause[101];
    char code[500];
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>temp;
        len=temp.length();
        pos=0;
        for(j=0;j<len;j++)
        {
            setCode(temp[j],pos,code);
            //setPause(temp[j],j,pause);
                switch(ch)
                {
                case 'A':
                      pause[j]=2;
                    break;
                 case 'B':
                    pause[j]=4;
                    break;
                case 'C':
                    pause[j]=4;
                    break;
                 case 'D':
                     pause[j]=3;
                    break;
                case 'E':
                    pause[j]=1;
                    break;
                  case 'F':
                     pause[j]=4;
                     break;
                case 'G':
                     pause[j]=3;
                       break;
                  case 'H':
                      pause[j]=4;
                     break;
                case 'I':
                    pause[j]=2;
                      break;
                case 'J':
                     pause[j]=4;
                    break;
                case 'K':
                    pause[j]=3;
                    break;
                   case 'L':
                    pause[j]=4;
                    break;
                  case 'M':
                    pause[j]=2;
                    break;
                 case 'N':
                    pause[j]=2;
                     break;
                 case 'O':
                    pause[j]=3;
                    break;
                case 'p':
                      pause[j]=4;
                    break;
                  case 'Q':
                    pause[j]=4;
                    break;
                case 'R':
                    pause[j]=3;
                    break;
                case 'S':
                    pause[j]=3;
                     break;
                 case 'T':
                    pause[j]=1;
                     break;
                case 'U':
                    pause[j]=3;
                    break;
                   case 'V':
                    pause[j]=4;
                    break;
                case 'W':
                    pause[j]=3;
                    break;
                case 'X':
                    pause[j]=4;
                    break;
                case 'Y':
                    pause[j]=4;
                    break;
                case 'Z':
                    pause[j]=4;
                    break;
                case '_':
                    pause[j]=4;
                    break;
                case '?':
                    pause[j]=4;
                    break;
                case '.':
                    pause[j]=4;
                    break;
                case ',':
                    pause[j]=4;
                    break;
                }
        }
        cout<<i+1<<": ";
        printCode(code,pause,len);
        cout<<endl;
    }
    return 0;
}

void setCode(char ch,int &pos,char &code[])
{
    switch(ch)
    {
    case 'A':
        code[pos++]='.';
        code[pos++]='-';
        break;
    case 'B':
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='.';
        break;
    case 'C':
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='.';
        break;
    case 'D':
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='.';
        break;
    case 'E':
        code[pos++]='.';
        break;
    case 'F':
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='.';
        break;
    case 'G':
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='.';
        break;
    case 'H':
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='.';
        break;
    case 'I':
        code[pos++]='.';
        code[pos++]='.';
        break;
    case 'J':
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='-';
        break;
    case 'K':
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='-';
        break;
    case 'L':
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='.';
        break;
    case 'M':
        code[pos++]='-';
        code[pos++]='-';
        break;
    case 'N':
        code[pos++]='-';
        code[pos++]='.';
        break;
    case 'O':
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='-';
        break;
    case 'P':
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='.';
        break;
    case 'Q':
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='-';
        break;
    case 'R':
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='.';
        break;
    case 'S':
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='.';
        break;
    case 'T':
        code[pos++]='-';
        break;
    case 'U':
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='-';
        break;
    case 'V':
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='-';
        break;
    case 'W':
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='-';
        break;
    case 'X':
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='-';
        break;
    case 'Y':
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='-';
        break;
    case 'Z':
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='.';
        break;
    case '_':
        code[pos++]='.';
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='-';
        break;
    case ',':
        code[pos++]='.';
        code[pos++]='-';
        code[pos++]='.';
        code[pos++]='-';
        break;
    case '?':
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='-';
        break;
    case '.':
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='-';
        code[pos++]='.';
        break;
    }
}
/*
void setPause(char ch,int j,int pause[]);
{
    switch(ch)
    {
    case 'A':
        pause[j]=2;
        break;
    case 'B':
        pause[j]=4;
        break;
    case 'C':
        pause[j]=4;
        break;
    case 'D':
        pause[j]=3;
        break;
    case 'E':
        pause[j]=1;
        break;
    case 'F':
        pause[j]=4;
        break;
    case 'G':
        pause[j]=3;
        break;
    case 'H':
        pause[j]=4;
        break;
    case 'I':
        pause[j]=2;
        break;
    case 'J':
        pause[j]=4;
        break;
    case 'K':
        pause[j]=3;
        break;
    case 'L':
        pause[j]=4;
        break;
    case 'M':
        pause[j]=2;
        break;
    case 'N':
        pause[j]=2;
        break;
    case 'O':
        pause[j]=3;
        break;
    case 'p':
        pause[j]=4;
        break;
    case 'Q':
        pause[j]=4;
        break;
    case 'R':
        pause[j]=3;
        break;
    case 'S':
        pause[j]=3;
        break;
    case 'T':
        pause[j]=1;
        break;
    case 'U':
        pause[j]=3;
        break;
    case 'V':
        pause[j]=4;
        break;
    case 'W':
        pause[j]=3;
        break;
    case 'X':
        pause[j]=4;
        break;
    case 'Y':
        pause[j]=4;
        break;
    case 'Z':
        pause[j]=4;
        break;
    case '_':
        pause[j]=4;
        break;
    case '?':
        pause[j]=4;
        break;
    case '.':
        pause[j]=4;
        break;
    case ',':
        pause[j]=4;
        break;
    }
}
*/
void printCode(char code,int pause[],int len)
{
    int i,j,c,tree;
    string temp;
    for(i=len-1,c=0;i>=0;i--)
    {
        tree=1;
        for(j=1;j<pause[i];j++)
        {
            if(code[c]=='-')
                tree=tree*2;
            else tree=tree*2+1;
            c++;
        }
        cout<<chTree[tree];
    }
}



為什麽 全局變量chTree數組不能這樣子定義每一個元素
問題究竟出在哪裡?
還有就是setCode函數 參數為什麽不能用引用 char &code[] 如果去掉&符號編譯又少了很多錯誤

謝謝各位大牛的回答
搜索更多相关主题的帖子: chTree char int void 
2008-02-06 11:37
快速回复:請教一個程序,不知道為什麽編譯不過
数据加载中...
 
   



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

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