C语言指针把小写变成大写

来源:百度知道 编辑:UC知道 时间:2024/06/08 13:02:30
#include<stdio.h>
#include<string.h>
void main()
{int i=0,k;
char string[100];
printf("please input one string whose members should not be more than 100:\n");
scanf("%s",string);
k=strlen(string);
while(*(string+i)!='\0')
{if('a'<=*(string+i)<='z')
{string[i]=string[i]-32;}i++;}
printf("all the menbers of the array reversely are:\n");
for(i=k-1;i>=0;i--)
printf("%-3c",string[i]);}
当输入大写时就输不出大写了,输出些其他字符,请各位高手找哈错误,万分感激
可以说明一下吗??谢谢

判断语句的问题
把if('a'<=*(string+i)<='z')改成if(*(string+i)>='a'&&*(string+i)<='z')

#include<stdio.h>
#include<string.h>
int main() {
int i=0,k;
char string[100];
printf("please input one string whose members should not be more than 100:\n");
scanf("%s",string);
k=strlen(string);
while (*(string+i)!='\0') {
if ('a' <= *(string+i) && *(string+i) <= 'z') { ///////////////
string[i]=string[i]-32;
}
i++;
}
printf("all the menbers of the array reversely are:\n");
for (i=k-1;i>=0;i--)
printf("%-3c",string[i]);
}

{if('a'<=*(string+i)<='z')错了,C语言没有这样的语法。
写成{'a' <= *(string+i) && *(string+i) <= 'z'}就行。