Header Ads

Input & Output:Getchar & putchar:C Programming Language - Part 3.0-3.1

Getchar & putchar



Until then we have shown in some data consoles. Used for printf In addition to printf there are a number of library functions that can show the output. Such as putchar, puts Also, we may have to take any data input from the user in our program. There is no data input from the user to getchar, scanf, gets In this chapter we will learn how to use them.

Getchar:
The input from the getchar Function is taken on the single character computer. This is a library function. It is usually written as a simple one.

1
Character variable = getchar ();
It is written as follows:

1
2
Char x;
X = getchar ();
Here char x; This implies that it is a character type variable Next to x = getchar (); By the value of x, the input device will be [keyboard]. See the following program

1
2
3
4
5
6
7
8
9
#include & lt; stdio.h & gt;
Int main ()
{
Char x;
Printf ("Enter a character:");
 X = getchar ();
 Return 0;
}
Run the program above and type a letter from the keyboard and press the Enter key. Can not find any output. Because we have inputs. Did not output. Let's use another function putchar for output.

Putchar Function:
The putchar function is used to display a single character on the console. It's a lot like getchar function. It is usually written as a lot.

1
Putchar (character variable);
In the program it is written as follows:

1
2
Char x = 'x';
Putchar (x);
Like the getchar function, here char x means that it is a caracterial data type variables. Later putchar (x); By the value of x will show on the output device.

1
2
3
4
5
6
7
8
#include & lt; stdio.h & gt;
Int main ()
{
 Char x;
 X = getchar ();
 Putchar (x);
 Return 0;
}
In the above program we got a character variable x. Now after running the program, whatever you input, the putchar function will show it on the console.

Turning lowercase letters into uppercase

1
2
3
4
5
6
7
8
9
#include & lt; stdio.h & gt;
Int main ()
{
 Char x;
 X = getchar ();
 Putchar (toupper (x));
 Return 0;
}
In this program, Character as input will give uppercase output to uppercase. And if it is big, it will output uppercase letters. But if you give any number then output will be.

Here we have used the toupper () library function. From the name of its work can not understand?

Make bigger letters smaller

1
2
3
4
5
6
7
8
9
#include & lt; stdio.h & gt;
Int main ()
{
Char x;
X = getchar ();
Putchar (tolower (x));
Return 0;
}
The lowercase means that the lowercase letter output in the program that character will take as input. And if you have a little bit of it, then output it. The tolower function has been used.


No comments

Theme images by sebastian-julian. Powered by Blogger.