Write a program that can directly Connect The keyboard character, if it is lowercase characters on the output corresponding uppercase characters, if you receive uppercase characters, the output corresponding lowercase characters, if the number is not output.
Program 1:
#include <stdio.h>
int Main ()
{
int t = 0;
printf ("Please enter a character:");
t = GetChar ();
if (t >= ' a '&&t <= ' z ')
{
Putchar (T-32);
}
Else if(t >= ' A '&&t <= ' Z ')
{
Putchar (t + 32);
}
Else if (t >= ' 0 '&&t <=' 9 ')
{
;
}
printf ("\ n");
return 0;
}
Result 1:
Please enter a character:a
A
Please press any key to continue ...
Result 2:
Please enter a character:D
D
Please press any key to continue ...
Result 3:
Please enter a character:5
Please press any key to continue ...
Program 2:
#include <stdio.h>
int Main ()
{
int t = 0;
printf ("Please enter a character: \ n");
while ((t = GetChar ())! = EOF) //!= EOF means the file is not over yet
{
if (t >= ' a '&&t <= ' z ')
{
Putchar (T-32);
}
Else if (t >= ' A '&&t <= ' Z ')
{
Putchar (t + 32);
}
Else if (t >= ' 0 '&&t <= ' 9 ')
{
;
}
Else
{
Putchar (t);
}
}
printf ("\ n");
return 0;
}
Results:
Please enter a character:
F
F
N
N
8
This article is from the "Rock Owl" blog, please be sure to keep this source http://10742111.blog.51cto.com/10732111/1719758
C Language: Write a program that can receive keyboard characters directly