欢迎各界计算机爱好者加入,弘扬极客精神!

为什么子函数不能对主函数中的数组的数值进行修改

2 喜欢 2 不喜欢
void displayBoard(int board[])
{
    int i,j;
    printf("\n");
    printf("   A B C|D E F|G H I\n");
    printf("  ------------------- \n");
    for(i=0;i<9;i++)
    {
        printf("%d ",i+1);
        for(j=0;j<9;j++)
        {
            if(j==0 || j==3 || j==6)
            {
                if(board[i*9+j]==0)
                {
                    printf("|.");
                }
                else
                {
                    printf("|%d",board[i*9+j]);
                }
            }
            if(j==8)
            {
                if(board[i*9+j]==0)
                {
                    printf(" .|");
                }
                else
                {
                    printf(" %d|",board[i*9+j]);
                }
            }
            if(j==1||j==2||j==4||j==5||j==7)
            {
                if(board[i*9+j]==0)
                {
                    printf(" .");
                }
                else
                {
                    printf(" %d",board[i*9+j]);
                }
            }
        }
        printf("\n");
        if(i==2||i==5||i==8)
        {
            printf("  |-----|-----|-----|\n");
        }
    }
}
 
void putNumber(int board[])
{
    int row,i,j,number;
    char col;
    printf("Add a number: ");
    scanf("%c%d",&col,&row);
    printf("\t");
    scanf("%d",&number);
    i=row-1;
    switch(col)
    {
    case 'A':
        j=0;
    case 'B':
        j=1;
    case 'C':
        j=2;
    case 'D':
        j=3;
    case 'E':
        j=4;
    case 'F':
        j=5;
    case 'G':
        j=6;
    case 'H':
        j=7;
    case 'I':
        j=8;
    }
    board[i*9+j]=number;
}
 
int main()
{
    int board[81]={9,0,4,0,0,5,6,0,0,
                   0,1,0,9,0,0,0,3,0,
                   8,5,7,0,0,3,0,0,0,
                   5,8,0,0,4,0,0,2,0,
                   3,0,0,0,9,0,0,0,7,
                   0,4,0,0,2,0,0,5,3,
                   0,0,0,4,0,0,1,8,6,
                   0,9,0,0,0,1,0,7,0,
                   0,0,8,7,0,0,5,0,9};
    putNumber(board);
    displayBoard(board);
    return 0;
}

 

问题关闭原因: 已解决
最新提问 3月 24, 2016 分类:C/C++ | 用户: For | Tomorrow (2,832 分)  
已关闭 3月 24, 2016 用户:For | Tomorrow
...