在一个字符数组中存放“AbcDEfg”字符串,编写程序,把该字符串中的小写字母变为大写字母,把该字符串中的

大写字母变为小写字母,用指针的方法进行编程 。用C语言

第1个回答  2011-04-28
#include <stdio.h>
#include <stdlib.h>
int main()
{
char chs[]={'a','B','c','E','F','k','V'};
char *p=chs;
int i=0;
for(i=0;i<sizeof(chs);i++)
{
if(*(p+i)>=97 && *(p+i)<=122)
{
//小写字母ascii码范围:97-122
*(p+i)=*(p+i)-32;
//转换为对应的大写字母
}
}
*(p+i)='\0';
printf("%s\n",chs);
return 0;
}本回答被提问者和网友采纳
第2个回答  2011-04-28
#include <stdio.h>
int main()
{
char a[10] = "AbcDEfg";
char *p;
printf("array:\n");
printf("%s\n",a);
p = a;
while(*p)
{
if(*p>='A'&&*p<='Z')
{
*p += 32;
p++;
continue;
}
if(*p>='a'&&*p<='z')
{
*p -= 32;
p++;
continue;
}
}
printf("new array:\n");
printf("%s\n",a);
return 0;
}

效果:
C:\Documents and Settings\Owner\桌面>t
array:
AbcDEfg
new array:
aBCdeFG
C:\Documents and Settings\Owner\桌面>
第3个回答  2011-04-28
toupper函数