我不知道为什么字符串中的输入大写字母会更改为随机代码
#include<stdio.h>
#include<string.h>
#define length 100
int main()
{
int count;
char word[length];
printf("Please input your word =");
scanf("%s", &word);
count=strlen(word);
int i;
for(i=0;i<=count;i++)
{
if(word[i]>=97||word[i]<=122)
{
word[i]+= -32;
}
printf(" %c",word[i]);
}
return 0;
}
答案 0 :(得分:3)
变化:
if(word[i]>=97||word[i]<=122)
要:
if(word[i]>=97 && word[i]<=122)
答案 1 :(得分:2)
你应该在条件中使用AND运算符而不是OR运算符。
if(word[i]>=97 && word[i]<=122) //to specify small character region's upper AND lower bound
可能会尝试使用
word[i] -= 32; //for simplicity
答案 2 :(得分:0)
|| -------“&amp;&amp;
#include<stdio.h>
#include<string.h>
#define length 100
int main()
{
int count;
char word[length];
printf("Please input your word =");
scanf("%s", word);
count=strlen(word);
int i;
for(i=0;i<count;i++)
{
if(word[i]>=97&&word[i]<=122)
{
word[i]+= -32;
}
printf(" %c",word[i]);
}
return 0;
}