簡體   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