Writing A Character in C lang
Posted by
Ravi Kumar at Friday, September 2, 2011
Share this post:
|
The function putchar is used for writing character
one at a time to the terminal.It takes the form as shown
below:
putchar(variable_name);
where variable_name is a type char variable containing
a character.
for example:
an='y';
putchar(an);
will display the character y on the screen.
The statement putchar('\n') ;
would cause the cursor on the screen to move to the
beginning of the next line.
program: /* Writing a character to the terminal */
#include
#include
main()
{
char alphabet;
printf("enter an alphabet");
putchar('\n');
alphabet=getchar();
if(islower(alphabet))
putchar(toupper(alphabet));
else
putchar(tolower(alphabet));
}
Output: enter an alphabet
a
A
enter an alphabet
R
r
Formatted input: Formatted input refer to an input data that
has been arranged in a particular format.
example:14.35 134 pinky
The first part of data should be read into a variable
float,the second into int,and the third part into char.
This is possible in C using the scanf function.
scanf("control string", arg1,arg2............argn);
the control string specifies the field format in which
the data is to be entered and the argument arg1,arg2,.......
argn specify the address of locations where the data is stored.
Control string contain field specification which direct the
interpretation of input data.
It may include:
field specifications,consisting of the conversion
character%, a data type character and an optional number,
specifying the field width.