本文介绍了我正在尝试打印我的char数组,但它只是打印数字为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
int counter;
char car[3]={'a','b','c',};
counter = 0;
while(counter < 3)
{
printf("%d\n",car[counter]);
counter++;
}
return 0;
What I have tried:
i have tried changing the values and trying different codes but nothing comes up it just gives me ramdon numbers on the output which i find annoying cuz the values are ABC
推荐答案
Quote:
printf(%d \ n,car [counter]);
printf("%d\n",car[counter]);
to
printf("%c\n",car[counter]);
查看 []。
顺便说一下,你得到的数字不是随机的。它们是 []对应字符'a'
,'b'
,'c'
。
Have a look at printf documentation[^].
By the way, the numbers you get are not random ones. They are the ASCII codes[^] corresponding to the characters 'a'
, 'b'
, 'c'
.
printf("%c\n",car[counter]);
这篇关于我正在尝试打印我的char数组,但它只是打印数字为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!