本文介绍了我怎么能写从用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循环单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:40