Input and output
If you know watched yesterday's lesson, then you should be fluent in integer input and output, so if I want to enter the characters how should we do?
After the query data, we know that define the character, we use char
, when to enter characters, we use%c
Now let's try to enter a
, and use %d
the output.
#include <stdio.h>
int main ()
{
char a;
scanf("%c",&a);
printf("%c\n",a);
return 0;
}
OUTPUT
a
97
We can see
when we enter a
the time of output is 97
when we enter is b
when the output is 98
b
in a
the back, while b
just more than a
large 1
, this should not be a coincidence.
Summary We experimentally obtained
letter | output value
| --- | --- |
| A | 97 |
| B | 98 |
| C | 99 |
| D | 100 |
So we boldly guess, the input after a +1, you can output b is not it?
#include <stdio.h>
int main ()
{
char a;
scanf("%c",&a);
printf("%c\n",a+1);
return 0;
}
OUTPUT
a
b
After verification, we can find our guess is right, let's try it enter capital letters.
#include <stdio.h>
int main ()
{
char a;
scanf("%c",&a);
printf("%d\n",a);
return 0;
}
OUTPUT
A
65
We can get through summary trials
letter | output value
| --- | --- |
| A | 65 |
| B | 66 |
It is not difficult to guess, to -32 lowercase letters, uppercase letters can be output.
#include <stdio.h>
int main ()
{
char a;
scanf("%c",&a);
printf("%c\n",a-32);
return 0;
}
OUTPUT
a
A
Learn who you should have learned basic input and output characters, and doing simple processing, if you want to know more things can go [Baidu Encyclopedia] [1] see.
[. 1]: https://baike.baidu.com/item/ASCII/309296?fr=aladdin