In the following article all formatted input and output functions in C programming as well as character input and output functions in C are discussed in detail. Along with this all console input output functions like printf(), scanf(), getch(), clrscr(), getchar(), putchar() are given here with their syntax and examples.
Console Input Output Functions:
What is mean by console?
- We can say console is an interface or screen of operating system form which we can communicate with operating system.
- Input means whichever instructions we give to the computer and after process we get desired result is output, for that purpose we are using input and out functions in programming.
- While in C programming, there is collection of functions where we can pass the number of arguments like main() function.
Console Input Output Functions includes the user program by using the header file stdio.h, which stands for standard input-output.header.
Input through keyboard and result on screen, together we say it as Console.
Types of Console Input Output Functions:
There are two types of Console Input Output Functions as:
1. Formatted input/output functions
2. Character input/output functions
A] Formatted input/output functions:
1. scanf():
- scanf() is used to read values standard input device such as keyboard.
Syntax :
scanf(“format string”, &variable1,&variable2,&variable3,…&variable n);
where “format string” represents the format specification,
symbol & (ampersand) which represents the memory address where the variable value is to be stored.
Example :
- scanf(“%d%f”, &a,&b);
- scanf(“%c”, &school);
- scanf(“%s”, str);
Data type
|
Format |
Meaning
|
Int
|
%d |
Decimal integer value |
|
%u |
Unsigned integer value |
|
%o |
Unsigned octal value |
|
%x |
Unsigned hexadecimal value |
float |
%f |
Floating Point value |
char |
%c |
Single character value |
|
%s |
String value
|
2. printf():
- printf() is used to display values using the standard output device such as monitor.
Syntax:
printf(“format string”, variable1,variable2,variable3,…variablen);
Example:
- printf(“%d”, a);
- printf(“%f”, x);
B] Character input/output functions:
1. getch():
- getch() is used to read a character from the keyboard.
Syntax :
ch=getch();
Example:
char cr;
cr=getch();
2. getchar() Function:
- getchar() is read one character at a time from input device.
Syntax :
ch=getchar();
3. putchar() Function:
- putchar() displays one character at a time on the monitor screen.
Syntax :
putchar(ch);
Example :
char c=’A’;
putchar(c);
4. gets():
- gets() reads a string of characters including white spaces.
Syntax :
gets(str);
Example :
char str[25];
gets(str);
5. puts() :
- puts() displays a character string on the screen.
Syntax :
puts(str);
Example :
char str[20]=” Hi dude!”
puts(str);
6. clrscr():
- clrscr() is used to clear the monitor screen.
Syntax :
clrscr();
Note: It is important that you must include the header file <conio.h> in the program.
Write a C program to implement these functions.
#include<stdio.h>
#include<conio.h>
void main()
{
int num, sqr;
clrscr()
printf(“\n Enter value of number:”);
scanf(“%d”,&num);
sqr=num*num;
printf(“\n Square of a given number=%d”,sqr);
getch();
}
Related Articles:
- Basic Accounting Concepts Part 1
clrscr in cconsolformat specifiers in cformatted input and output in cgetchar function in cgetchar in cprintf and scanf in cputchar in cscanf function in c
Formatted input and output in C | Consol
2022-11-18
Computer Basics
No Comments
Admin
In the following article all formatted input and output functions in C programming as well as character input and output functions in C are discussed in detail. Along with this all console input output functions like printf(), scanf(), getch(), clrscr(), getchar(), putchar() are given here with their syntax and examples.
Console Input Output Functions:
What is mean by console?
Console Input Output Functions includes the user program by using the header file stdio.h, which stands for standard input-output.header.
Input through keyboard and result on screen, together we say it as Console.
Types of Console Input Output Functions:
There are two types of Console Input Output Functions as:
1. Formatted input/output functions
2. Character input/output functions
A] Formatted input/output functions:
1. scanf():
Syntax :
scanf(“format string”, &variable1,&variable2,&variable3,…&variable n);
where “format string” represents the format specification,
symbol & (ampersand) which represents the memory address where the variable value is to be stored.
Example :
Data type
Meaning
Int
String value
2. printf():
Syntax:
printf(“format string”, variable1,variable2,variable3,…variablen);
Example:
B] Character input/output functions:
1. getch():
Syntax :
ch=getch();
Example:
char cr;
cr=getch();
2. getchar() Function:
Syntax :
ch=getchar();
3. putchar() Function:
Syntax :
putchar(ch);
Example :
char c=’A’;
putchar(c);
4. gets():
Syntax :
gets(str);
Example :
char str[25];
gets(str);
5. puts() :
Syntax :
puts(str);
Example :
char str[20]=” Hi dude!”
puts(str);
6. clrscr():
Syntax :
clrscr();
Note: It is important that you must include the header file <conio.h> in the program.
Write a C program to implement these functions.
#include<stdio.h>
#include<conio.h>
void main()
{
int num, sqr;
clrscr()
printf(“\n Enter value of number:”);
scanf(“%d”,&num);
sqr=num*num;
printf(“\n Square of a given number=%d”,sqr);
getch();
}
Related Articles:
Some More: DBMS/ WT/ DMDW
clrscr in cconsolformat specifiers in cformatted input and output in cgetchar function in cgetchar in cprintf and scanf in cputchar in cscanf function in c