小编use*_*599的帖子

在C中打印ASCII

我正在尝试编写一个程序,它将使用for循环打印出所有ASCII字符,但它会继续进行无限循环,除非我取出127,我做错了什么或是ASCII表现如何?

这将崩溃(无限循环):

#include <stdio.h>

int main (void)
{

for (char i = -128; i <= 127; i++)
{
    printf("%d = %c\n", i, i);
}

return 0;
}
Run Code Online (Sandbox Code Playgroud)

但这很好:

#include <stdio.h>

int main (void)
{

for (char i = -128; i < 127; i++)
{
    printf("%d = %c\n", i, i);
}

printf("%d = %c\n", 127, 127);

return 0;
}
Run Code Online (Sandbox Code Playgroud)

c ascii for-loop

0
推荐指数
1
解决办法
4505
查看次数

标签 统计

ascii ×1

c ×1

for-loop ×1