clear buffer memory in c / c++
To clear the buffer memory in C/C++, you can follow these steps:
Include the necessary header file:
#include <stdlib.h>
Use the
fflush()
function to clear the buffer memory. It takes a pointer to the file stream you want to clear. To clear the standard input buffer, usefflush(stdin)
. For example:
fflush(stdin);
- Alternatively, you can use the
getchar()
function to clear the buffer memory. It reads a single character from the standard input and discards it. For example:
int c;
while ((c = getchar()) != '\n' && c != EOF);
These steps will help you clear the buffer memory in C/C++.