我怎么能写从用C运行z和A到Z循环单? [英] How can I write a single for loop running from a to z and A to Z in C?

查看:106
本文介绍了我怎么能写从用C运行z和A到Z循环单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这两个for循环为单个环路相结合。我该怎么做?

I want to combine both the for loops into single for loop. How can i do that?

我想通过一个循环,Z和A到Z,像这样:

I want to loop through a to z, and A to Z, like so:

char ch;
for (ch = 'A' ; ch <= 'Z' ; ch++ )
{ 
}
for (ch = 'a' ; ch <= 'z' ; ch++ )
{
}

,但使用单个环路

but using a single loop.

推荐答案

我不亲自的这一解决方案,但是:

I don't personally like this solution, but:

char * letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for (char * ptr = letters; *ptr != 0; ++ptr) {
    char ch = *ptr;
    ...
} 

这篇关于我怎么能写从用C运行z和A到Z循环单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆