Buffer in C

Google Advertisements

Prev Tutorial Next Tutorial

Buffer in C

Temporary storage area is called buffer.

All standard input output devices are containing input output buffer.

In implementation when we are passing more than required number of values as a input then rest of all values will automatically holds in standard input buffer, this buffer data will automatically pass to next input functionality if it is exist.

Example

#include<stdio.h>
#include<conio.h>

void main()
{
int v1,v2;
clrscr();
printf("\n Enter v1 value: ");
scanf("%d",&v1);
printf("\n Enter v2 value: ");
scanf("%d",&v2);
printf("\n v1+v2=%d ",v1+v2);
getch();
}

Output

Enter v1 value: 10 Enter v2 value: 20 V1+v2=30 Again run program Enter v1 value: 10 20 30 Enter v2 value: V1+v2=30
Buffer

Explanation:

In the above example we pass three input in v1 and we cannot pass any value in v2 but value of v1 is automatically pass in v2.

In implementation when we need to remove standard input buffer data then go for flushall() or fflush() function.

flushall()

it is a predefined function which is declared in stdio.h. by using flushall we can remove the data from standard input output buffer.

fflush()

it is a predefined function in "stdio.h" header file used to flush or clear either input or output buffer memory.

fflush(stdin)

it is used to clear the input buffer memory. It is recommended to use before writing scanf statement.

fflush(stdout)

it is used to clear the output buffer memory. It is recommended to use before printf statement.

Example

#include<stdio.h>
#include<conio.h>
void main()
{
int v1,v2;
clrscr();
printf("\n Enter v1 value: ");
scanf("%d",&v1);
printf("\n Enter v2 value: ");
fflush(stdin);
scanf("%d",&v2);
printf("\n v1+v2=%d ",v1+v2);
getch();
}

Output

Enter v1 value: 10 20 30 Enter v2 value: 40 v1+v2=50
Buffer
Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. For Advertisement contact on [email protected] or 8076671483

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar. Difference between path and classpath in Java

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: [email protected] or 8076671483 Try this Keyword C++ Programs