有没有大佬用C语言写,请问这边scanf怎么修改啊

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

NJUCSER @ 2020-11-29 09:47:27

# include<stdio.h>
# include<math.h>
int main()
{
    char W[10][5][3] =//W[i][j][k]表示第i个数字的第j行的第k列
    {
        {//0
            'X','X','X',
            'X','.','X',
            'X','.','X',
            'X','.','X',
            'X','X','X',
        },
        {//1
            '.','.','X',
            '.','.','X',
            '.','.','X',
            '.','.','X',
            '.','.','X',
        },
        {//2
            'X','X','X',
            '.','.','X',
            'X','X','X',
            'X','.','.',
            'X','X','X',
        },
        {//3
            'X','X','X',
            '.','.','X',
            'X','X','X',
            '.','.','X',
            'X','X','X',
        },
        {//4
            'X','.','X',
            'X','.','X',
            'X','X','X',
            '.','.','X',
            '.','.','X',
        },
        {//5
            'X','X','X',
            'X','.','.',
            'X','X','X',
            '.','.','X',
            'X','X','X',
        },
        {//6
            'X','X','X',
            'X','.','.',
            'X','X','X',
            'X','.','X',
            'X','X','X',
        },
        {//7
            'X','X','X',
            '.','.','X',
            '.','.','X',
            '.','.','X',
            '.','.','X',
        },
        {//8
            'X','X','X',
            'X','.','X',
            'X','X','X',
            'X','.','X',
            'X','X','X',
        },
        {//9
            'X','X','X',
            'X','.','X',
            'X','X','X',
            '.','.','X',
            'X','X','X',
        }
    };
    char a[110];
    int n;
    scanf_s("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf_s("%c", &a[i]);
    }
    for (int i = 0; i < 5; i++) 
    {//枚举每一行
        for (int j = 0; j < n; j++) 
        {//枚举每一个数字
            for (int k = 0; k < 3; k++) 
            {//枚举每个数字的列
                printf("%c", W[a[j] - '0'][i][k]);//输出,因为s[j]为字符,所以要减去'0'
            }
            if (j != n - 1)
                printf("%c",'.');//如果最后一列,就不需要打印'.'
        }
        printf("\n");//换行
    }
    return 0;
}

by Ryo_Yamada @ 2020-11-29 09:50:22

@NJUCSER scanf_s(" %c", &a[i]);


by Ryo_Yamada @ 2020-11-29 09:52:25

为什么我这 scanf_s 编译不了啊(,改成 scanf 也可以


by NJUCSER @ 2020-11-29 09:52:51

@BreezeEnder 请问为什么前面要加空格啊~~~ 谢谢~


by NJUCSER @ 2020-11-29 09:53:41

@BreezeEnder scanf 他的编译器只认同scanf~


by Ryo_Yamada @ 2020-11-29 09:56:06

@NJUCSER scanf 读入 %c 的时候只读入 1 个字符,回车也会被当成字符,这个回车符是放在缓冲区的,而加上空格就就把缓冲区中的回车当成第一个字符,读取后丢掉。7


by Ryo_Yamada @ 2020-11-29 09:56:36

↑最后怎么多了一个 7 /fad


by NJUCSER @ 2020-11-29 09:57:20

@BreezeEnder 噢噢谢谢大佬~


by 小菜鸟 @ 2020-11-29 09:57:26

@NJUCSER scanf_s是C11标准,要加编译参数--std=c11


by 梦游的小雪球 @ 2020-11-29 09:59:21

@BreezeEnder %%%


|