Questions tagged [fflush]

The C standard library `fflush` is used to synchronize the stream on which it is invoked with the actual content of the corresponding file. It can be used only on output streams. A similar function is defined in C++ as `std::fflush`.

The C standard library function fflush function is defined in the <stdio.h> header and its documentation can be found here.

The corresponding C++ standard library function std::fflush is defined in <cstdio> header and documented here.

197 questions
1
vote
1 answer

python InputDevice fflush

I use python-evdev library for detect keyboard event. But I have a problem, I need flush the keyboard event after I have detect key. example: from evdev import InputDevice, categorize, ecodes dev = InputDevice('/dev/input/event1') for event in…
1
vote
2 answers

C++ Clear string

Hey guys i created a game, in the code it have while(true) and each time it gets as input a new string, The problem is that if i wrote first time abc and then in second loop abcd, and then abc it saves the last d, I tried str.clear(), i tried to put…
MaxDevelop
  • 637
  • 1
  • 4
  • 16
1
vote
1 answer

fflush() function not working with stdin

I'm sorry for this silly question. I have C program to prompt user to enter age and name and then print the age and name to the screen. This is my exercise that I read from book. This the program: #include int main (void) { int age; …
harianja
  • 63
  • 2
  • 8
1
vote
1 answer

C: Stdin - Removing Excess Data

Short version I want to get rid of excess user input from stdin but I understand fflush(stdin) is not recommended. I found this replacement: int ch; while ((ch = getchar()) != '\n' && ch != EOF); However, if there is no excess data to remove, this…
Arc676
  • 4,445
  • 3
  • 28
  • 44
1
vote
1 answer

Clear the current line, as with fflush(stdout) in C

I have a very long for loop, which prints out many lines of information. I would like to keep it to just one line that overwrites previous lines. I tried Console.out.flush() but it does not seem to work.
Yang
  • 6,682
  • 20
  • 64
  • 96
1
vote
1 answer

fflush(stdin) before gets() in c

Okay , i was solving a problem in code chef (very easy). It briefly states that : -A question as a string will be given , and another string has to be produced which does not have any letter used in question string. Uppercase and lowercase are…
Number945
  • 4,631
  • 8
  • 45
  • 83
1
vote
2 answers

Using xinetd/inetd, why should servers call fflush()?

All program on xinetd (which I've read) call fflush(). Why? For example, Inetd-Wikipedia #include #include int main(int argc, char **argv) { const char *fn = argv[1]; FILE *fp = fopen(fn, "a+"); if(fp == NULL) …
aki33524
  • 176
  • 1
  • 8
1
vote
5 answers

Program doesn't execute gets() after scanf(), even using fflush(stdin)

After wasting too much time searching why my program doesn't execute gets() after using scanf(), I found a solution which is to use fflush(stdin) after scanf() to enable gets() to get a string. The problem is that fflush(stdin) doesn't do what is…
Joe Hackerberg
  • 457
  • 7
  • 20
1
vote
1 answer

fflush(FILE *stream) not working?

while(1) { ch=fgetc(ft); if(ch==EOF) { break; } if(ch=='u') { fputc('b',ft); fflush(ft); } } I tried to replace character after u with b in a file pointed by *ft. This code runs fine but when I…
kevin gomes
  • 1,775
  • 5
  • 22
  • 30
1
vote
4 answers

Simple minishell, doesn't recognise "quit" to end program becasue of the way fgets works

I'm trying to write a minishell with this code: #include #include #include #define LINE_LEN 50 #define MAX_PARTS 50 int main () { char* token; char str[LINE_LEN]; char* arr[MAX_PARTS]; int i,j; printf("Write a…
Trouble-lling
  • 333
  • 5
  • 15
1
vote
2 answers

Verifying input, and clearing keyboard buffer

How would I be able to clear the buffer if a character or more is entered in this block of code. int x = 1; float grade = 0.0; do { printf ("Enter a grade for quiz %d: ", x); scanf ("%f", grade); if (grade >= 1 && grade <= 10) break; …
1
vote
4 answers

fflush(stdin) does not work compiled with gcc in cygwin but does compiled with visual studio 2010

I am (re-)learning programming and I started with C. My IDE (if I may say so) is cygwin (32Bit) and Visual-Studio 2010 both on Windows7. I am always compiling the code I write with gcc (cygwin) as well as with the VS2010 compiler. I do so, I guess,…
user3010324
  • 63
  • 1
  • 5
1
vote
1 answer

fflush on stderrr causes program to crash

I am redirecting stderr to a log file on Windows Phone Runtime: int stdError = 0; FILE* pLogFile = NULL; // Redirect stderror to a logfile if ( ! m_logFilePath.empty( ) ) { // Get a duplicate file descriptor for stderror // This returns -1…
ssk
  • 9,045
  • 26
  • 96
  • 169
1
vote
2 answers

fseek(stdin,0,SEEK_SET) and rewind(stdin) REALLY do flush the input buffer "stdin".Is it OK to use them?

I was thinking since the start that why can't fseek(stdin,0,SEEK_SET) and rewind(stdin) flush the input buffer since it is clearly written in cplusplusreference that calling these two functions flush the buffer(Input or Output irrespective).But…
Jugni
  • 255
  • 5
  • 12
1
vote
1 answer

scanf is skipped even if using fflush

I have a scanf that doesn't accept input. The value is automatically zero, even if the variable wasn't initialized. The scanf is skipped: printf("\nEnter the number of the student to be dropped: "); fflush(stdin); scanf(" %d…