-2

如何编写一个运行单个字符所有可能值的程序?例如,A、B、C、D 等,甚至转到 '、:、/ 等。

4

4 回答 4

5

输出所有可打印 ASCII 字符的简单方法可能是:

for (char c = ' '; c < 0x7f; c++) {
    putchar(c);
}

可打印的 Unicode 字符集要大得多。

于 2012-09-23T01:06:37.963 回答
2
#include <stdio.h>
#include <ctype.h>

/* For ASCII */
for (int c = 0; c < 128; c++)
{
    if (isprint(c))
        putchar(c);
}
于 2012-09-23T01:33:07.833 回答
2
char aestheticChars = "ABCD':/"; // add whatever characters you consider aesthetic

char c, char* p;
for (p = aestheticChars; (c = *p) != '\0'; p++)
{
  // do something with c
}
于 2012-09-23T01:53:50.707 回答
-1

对于 ASCII,请查看http://www.cplusplus.com/reference/clibrary/cctype/以获取关于什么被认为是空白、什么被认为是字母数字、可打印、图形等的表格。然后遍历范围对你感兴趣。

@GregHewgill 的解决方案将为您提供所有“可打印”字符,但您可能需要对其进行调整以获取所有“图形”字符或所有“字母数字”字符。

于 2012-09-23T01:26:22.480 回答