输出所有可打印的字符(附大小写字母)

#include <stdio.h>
#include <limits.h>
#include <wchar.h>
#include <ctype.h>
#include <wctype.h>

int main()
{
	int count = 0;
	char ch = '0';
	printf("\nThe printable characters are the following:\n");
	for(int code = 0; code <= CHAR_MAX; code++)//这里 code不能是char类型,否则在最后一次正确的迭代中,
											   //code==CHAR_MAX,此后给CHAR_MAX加1会得到0,将无限循环。
	{
		ch = (char)code;//故意强制转换的
		if(isprint(ch))
		{
			if(count++ % 32 == 0) printf("\n");//每次输出32个字符后换行
			printf("%c", ch);
		}
	}
	count = 0;
	wchar_t wch = '0';
	wprintf(L"\n\nThe alphabetic characters and their codes are the following:\n");
	for(wchar_t wch = L'a'; wch <= L'z'; wch++)
	{
		if(count++ % 3 == 0) wprintf(L"\n");
		wprintf(L"%lc %#x %lc %#x", wch, (long)wch, towupper(wch), (long)towupper(wch));
	}
	getchar();
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值