почему я не могу перевести все слова в верхний регистр C

Я не знаю, почему вводимые заглавные буквы в строке заменяются случайным кодом

#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;
}

-5

Решение

Изменить:

if(word[i]>=97||word[i]<=122)

Для того, чтобы:

if(word[i]>=97 && word[i]<=122)
3

Другие решения

Вы должны использовать оператор 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

|| ——- » &&

#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
По вопросам рекламы ammmcru@yandex.ru
Adblock
detector