转换为低级到高级 [英] conversion of lower to upper
本文介绍了转换为低级到高级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include< stdio.h>
#define islower(c)('a'< =(c)&&(c)< ='z')
#define toupper(c)(islower(c)?(c) - ('a' - 'A'):( c))
int main()
{
char * p = < span class =code-string> 我很好;
while (* p)
printf( %C跨度>,在toupper(* p ++));
return 0 ;
}
答案是AFE。
有人可以解释一下吗?
解决方案
嗯。
您确实认识到#define与函数不同调用?
所以当你传递一个自动递增的参数时,每次在扩展中使用它时它会自动递增吗?
所以你的代码扩展为:
printf( %c,( islower(* p ++)?(* p ++) - (' a' - ' A'):( * p ++)));并且较低也会扩展...
现在更有意义吗? :笑:
#include<stdio.h>
#define islower(c) ( 'a' <=(c) && (c)<= 'z' )
#define toupper(c) (islower(c)?(c)-( 'a' - 'A' ):(c))
int main()
{
char *p="i am fine";
while(*p)
printf("%c",toupper(*p++));
return 0;
}
answer is AFE.
can someone explain?
解决方案
Um.
You do realise that #define is not the same as a function call?
So when you pass a parameter that auto-increments, it auto-increments each time it is used within the expansion?
So your code expands to:
printf("%c",(islower(*p++)?(*p++)-( 'a' - 'A' ):(*p++)));And is lower expands as well...
Make a bit more sense now? :laugh:
这篇关于转换为低级到高级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文