求助这段#define与条件编译代码

2025-03-29 01:52:24
推荐回答(1个)
回答1:

#include
#include
#define LETTER 1
int main()
{
char str[20]="C Language",c;
int i;
i=0;
while((c=str[i])!='\0') //括号括错地方了
{

#if LETTER
if(c>='a'&&c<='z')
c-=32;
#else
if(c>'A'&&c<='Z')
c+=32;
#endif
printf("%c",c);
++i; //放在下面
}
system("pause");
return 0;
}

#if LETTER
#else
#endif
作用就是当LETTER为非0,执行#else 0就执行endif