繁体   English   中英

C,获取unsigned char以使用ascii 2表

[英]C, get unsigned char to use ascii 2 table

所以我想要的是使用unsigned char数组来显示ascii 2表。 继承人我拥有什么,什么不工作:

unsigned char digits[100];
int i=0;
while (i<=100)
{
printf("\n%c",digits[i]+48);
i++;
}

到目前为止很简单的代码。 但是根本不工作。

有什么建议么?

问题是digits[i]没有初始化。

如果您所做的只是显示ASCII表,则根本不需要该数组。

无需使用阵列。 这将有效:

int i=0;
while (i<=100){
    printf("\n%c", i + '0');
    i++;
}

此外,您的阵列未初始化。

#include <stdio.h>

int main(void){
    unsigned char digits[100] = { 1,0,2,4 };
    int i=0;

    while (i<100){
        printf("\n%c",digits[i++]+'0');
    }

    printf("\ninput number:");
    fgets(digits, 100, stdin);

    i=0;
    while(digits[i] && digits[i] != '\n')
        printf("\n%c", digits[i++]);

    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM