为什么显示return value 3221225477

P5730 【深基5.例10】显示屏

splendid_followers @ 2021-03-27 15:35:21

#include<iostream>
using namespace std;
int main()
{
    int n;
    char xsp[6][4*n+1];
    cin>>n;
    char c[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>c[i];
    }
    for(int i=1;i<=5;i++)
    {
        for(int j=1;j<=4*n;j++)
        {
            xsp[i][j]='X';
        }
    }
    for(int j=1;j<=(4*n);j++)
    {
        if(j%4==0)
        {
            xsp[1][j]='.';xsp[2][j]='.';xsp[3][j]='.';xsp[4][j]='.';xsp[5][j]='.';
        }   
    }
    for(int i=1;i<=n;i++)
    {
        int sg;
        sg=1+(i-1)*4;
        switch (c[i])
        {
            case '0':
                xsp[1][sg]='X';xsp[1][sg+1]='X';xsp[1][2+sg]='X';
                xsp[2][sg]='X';xsp[2][1+sg]='.';xsp[2][2+sg]='X';
                xsp[3][sg]='X';xsp[3][1+sg]='.';xsp[3][2+sg]='X';
                xsp[4][sg]='X';xsp[4][1+sg]='.';xsp[4][2+sg]='X';
                xsp[5][sg]='X';xsp[5][1+sg]='X';xsp[5][2+sg]='X';
                break;
            case '1':
                xsp[1][sg]='.';xsp[1][sg+1]='.';xsp[1][2+sg]='X';
                xsp[2][sg]='.';xsp[2][1+sg]='.';xsp[2][2+sg]='X';
                xsp[3][sg]='.';xsp[3][1+sg]='.';xsp[3][2+sg]='X';
                xsp[4][sg]='.';xsp[4][1+sg]='.';xsp[4][2+sg]='X';
                xsp[5][sg]='.';xsp[5][1+sg]='.';xsp[5][2+sg]='X';
                break;
            case '2':
                xsp[1][sg]='X';xsp[1][sg+1]='X';xsp[1][2+sg]='X';
                xsp[2][sg]='.';xsp[2][1+sg]='.';xsp[2][2+sg]='X';
                xsp[3][sg]='X';xsp[3][1+sg]='X';xsp[3][2+sg]='X';
                xsp[4][sg]='X';xsp[4][1+sg]='.';xsp[4][2+sg]='.';
                xsp[5][sg]='X';xsp[5][1+sg]='X';xsp[5][2+sg]='X';
                break;
            case '3':
                xsp[1][sg]='X';xsp[1][sg+1]='X';xsp[1][2+sg]='X';
                xsp[2][sg]='.';xsp[2][1+sg]='.';xsp[2][2+sg]='X';
                xsp[3][sg]='X';xsp[3][1+sg]='X';xsp[3][2+sg]='X';
                xsp[4][sg]='.';xsp[4][1+sg]='.';xsp[4][2+sg]='X';
                xsp[5][sg]='X';xsp[5][1+sg]='X';xsp[5][2+sg]='X';
                break;
            case '4':
                xsp[1][sg]='X';xsp[1][sg+1]='.';xsp[1][2+sg]='X';
                xsp[2][sg]='X';xsp[2][1+sg]='.';xsp[2][2+sg]='X';
                xsp[3][sg]='X';xsp[3][1+sg]='X';xsp[3][2+sg]='X';
                xsp[4][sg]='.';xsp[4][1+sg]='.';xsp[4][2+sg]='X';
                xsp[5][sg]='.';xsp[5][1+sg]='.';xsp[5][2+sg]='X';
                break;
            case '5':
                xsp[1][sg]='X';xsp[1][sg+1]='X';xsp[1][2+sg]='X';
                xsp[2][sg]='X';xsp[2][1+sg]='.';xsp[2][2+sg]='.';
                xsp[3][sg]='X';xsp[3][1+sg]='X';xsp[3][2+sg]='X';
                xsp[4][sg]='.';xsp[4][1+sg]='.';xsp[4][2+sg]='X';
                xsp[5][sg]='X';xsp[5][1+sg]='X';xsp[5][2+sg]='X';
                break;
            case '6':
                xsp[1][sg]='X';xsp[1][sg+1]='X';xsp[1][2+sg]='X';
                xsp[2][sg]='X';xsp[2][1+sg]='.';xsp[2][2+sg]='.';
                xsp[3][sg]='X';xsp[3][1+sg]='X';xsp[3][2+sg]='X';
                xsp[4][sg]='X';xsp[4][1+sg]='.';xsp[4][2+sg]='X';
                xsp[5][sg]='X';xsp[5][1+sg]='X';xsp[5][2+sg]='X';
                break;
            case '7':
                xsp[1][sg]='X';xsp[1][sg+1]='X';xsp[1][2+sg]='X';
                xsp[2][sg]='.';xsp[2][1+sg]='.';xsp[2][2+sg]='X';
                xsp[3][sg]='.';xsp[3][1+sg]='.';xsp[3][2+sg]='X';
                xsp[4][sg]='.';xsp[4][1+sg]='.';xsp[4][2+sg]='X';
                xsp[5][sg]='.';xsp[5][1+sg]='.';xsp[5][2+sg]='X';
                break;
            case '8':
                xsp[1][sg]='X';xsp[1][sg+1]='X';xsp[1][2+sg]='X';
                xsp[2][sg]='X';xsp[2][1+sg]='.';xsp[2][2+sg]='X';
                xsp[3][sg]='X';xsp[3][1+sg]='X';xsp[3][2+sg]='X';
                xsp[4][sg]='X';xsp[4][1+sg]='.';xsp[4][2+sg]='X';
                xsp[5][sg]='X';xsp[5][1+sg]='X';xsp[5][2+sg]='X';
                break;
             case '9':
                xsp[1][sg]='X';xsp[1][sg+1]='X';xsp[1][2+sg]='X';
                xsp[2][sg]='X';xsp[2][1+sg]='.';xsp[2][2+sg]='X';
                xsp[3][sg]='X';xsp[3][1+sg]='X';xsp[3][2+sg]='X';
                xsp[4][sg]='.';xsp[4][1+sg]='.';xsp[4][2+sg]='X';
                xsp[5][sg]='X';xsp[5][1+sg]='X';xsp[5][2+sg]='X';
                break;
        }

    }
    for(int i=1;i<=5;i++)
    {
        for(int j=1;j<=4*n;j++)
        {
            cout<<xsp[i][j];
        }
        cout<<endl;
    }
    return 0;
}

by Argon_Cube @ 2021-03-27 15:41:02

@大帅哥傅建聪 \texttt{0xC0000005(3221225477)}(EXCEPTION_ACCESS_VIOLATION):程序试图访问一个它没有访问权限的地址(访问违规)。


by splendid_followers @ 2021-03-27 15:45:56

@Unnamed_Cube 刚刚百度了下应该是数组的大小出错了,我后来改成全局变量然后下标写大一些就没有问题了,谢谢啦!


|