Answer the question
In order to leave comments, you need to log in
How to find out in C whether the entered 1) string 2) character is in upper case or lower case?
I can’t figure out how to make a number out of a letter, that is, so that the character matches the character in the ASCII table; and then, how to use an array to make data input, that is, not char but a full-fledged string, so that a string is entered immediately and not a character
char name;
scanf("%s",name);
for (i=1;i<=strlen(name);i++){
if (name >= 97 && name <= 122)
{
printf("lower");
name -=32;
printf("now it is upper");
}
if (name >= 65 && name <=90)
{
printf("upper");
name +=32;
printf("now it is lower");
}
}
Answer the question
In order to leave comments, you need to log in
Just declare the variable as char name[100];
After that, refer not to name, but to name[i]
Well, to get the numeric value of the symbol, it is enough to write int (c) or in your case int (name[i])
> how to use an array to make data input, that is, not char but a full-fledged string, so that a string is entered immediately and not a character
char s[100];
scanf("%99s", s);
len = strlen(s);
for (i = 0; i < len; ++i) {
name = s[i];
// обработай как-нибудь наш name…
}
scanf("%s",name);
scanf("%c", &name);
. To enter a bunch of characters - I wrote above. for (i=1;i<=strlen(name);i++) {
'\0'
, i.e. its complexity is O(n). It is necessary to store the length in a separate variable. char* p;
for (p = s; *p != '\0' ++p) {
if (name >= 97 && name <= 122)
if (name >= 'a' && name <= 'z')
:? The constants 'a' and 'z' are the same int in C, char in C++ (probably for compatibility with function overloading).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question