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
0
votes
4 answers

fflush and 'no disk space left'

I'm writing a program, some kind of database. While I was reading manual of fclose(3) I found that it calls fflush(3) to flush FILE* buffers to disk (actually to OS buffer, but it doesn't matter right now, we can always call fsync(2)). Because I'm…
f0b0s
  • 2,978
  • 26
  • 30
0
votes
2 answers

Proper char handling

When compiling to Linux with gcc, everytime the user inputs whatever answer, the program reaches the same part of the code in other iteration but doesn't waits for the input of the user, and instead feeds a newline to the scanf function, making the…
agxxvi
  • 39
  • 6
0
votes
1 answer

fflush() does not flush properly

I'm creating a very simple program execution timer in C. I'll provide sample code below. The problem is that the fflush(NULL) doesn't flush every "Hello World\n" from the stdout when ending a program with Ctrl+C (i.e. SIGINT signal). They still…
Jori
  • 1,122
  • 2
  • 18
  • 36
0
votes
2 answers

Having trouble implementing forever loop

I seems to be having trouble with the forever loop, it seems to be working the first time i run the program but for some reason it seems to skip the option of asking the user if they would like to enter anymore CDs... Any help would be appreciated,…
mvitagames
  • 413
  • 3
  • 6
  • 16
0
votes
2 answers

How come fflush(stdin) function is not working?

My main question is why is it that the fflush(stdin); function not working? Whenever I run the the code, I am not able to get the second input with space ex. Hello World but instead I get Hello?? thanks #include main(){ int …
mvitagames
  • 413
  • 3
  • 6
  • 16
0
votes
3 answers

clock using fflush is not clearing screen

I am trying to make a clock in C, but the screen is not properly clearing, it just keeps printing to a new line. How am I improperly using fflush? #include #include #include int main() { while (1) { time_t…
kyle k
  • 5,134
  • 10
  • 31
  • 45
0
votes
1 answer

How to use fflush(stdin) in a simple tic tac toe input?

I'm new to C programming and I have this task that requires me to create a simple tic-tac-toe game. I managed to create an empty board with arrays and loops. Now I am required to get the input of the user, and place the 'X'/'O' into the board. Here…
Sam Liew
  • 157
  • 2
  • 4
  • 15
0
votes
2 answers

scanf gets skipped, even with safeties (getchar())

I know this question gets asked a hundred times over, and I've scoured all of the possibilities, but I guess I'm not adept enough to know where this problem lies. I'm programming a program where I need to fill a struct with data (ints and strings).…
Ghijs Kilani
  • 166
  • 1
  • 9
0
votes
0 answers

How to make fprintf and fflush more effective?

I want to write a logger for my server. I am using the fprintf function to write a log file. If my server crashes, then the buffer can't flush, so I can't get the last text from buffer. If i call fflush function after fprintf every time, is that a…
Quine
  • 1
0
votes
1 answer

Is there any difference without fflush in that code?

In cpp reference, it claims fflush is: Causes the output file stream to be synchronized with the actual contents of the file. Indeed, I don't understand what it means. I just wonder, in that code, if I take out fflush, is there any difference? I…
Sayakiss
  • 6,878
  • 8
  • 61
  • 107
0
votes
1 answer

How to avoid fflush on stdout from hanging when disk is full?

I have a situation where disk becomes full and my program hangs because of fflush being used on stdout. I have put down a small code to mimic the problem. We have to redirect this programs stdout to a file in a disk whose size is full…
0
votes
2 answers

C, Different GCC, fflush() not working?

I'm a beginner programmer. I have a function that doesn't let float numbers or characters to be inputted. It was working fine with gcc 3.4.2, but now I updated to 4.7.1 and it isn't working properly. It only works now with the first input a[0]. If I…
0
votes
1 answer

IO redirection and buffer issues, fflush and c

for my class we are to implement a shell with output redirection. I have the output redirection working, except my first command is always corrupted see: $ echo this doesn't work H<@?4echo No such file or directory $ echo this does work this does…
Harrison
  • 430
  • 2
  • 6
  • 13
0
votes
1 answer

C: Synchronising two file pointers to the same file

I need two file pointers (FILE *) to operate alongside each other. One is to apply append operations and another is for reading and overwriting. I need appends to the file from one pointer to be recognised by the other file pointer so that the other…
Matthew Mitchell
  • 5,293
  • 14
  • 70
  • 122
0
votes
2 answers

file read from and file written to are not same

I am trying to read contents of a file that is some 3KB into a buffer and then writing the contents of the buffer into another file. The file in which data is written into contains only a part of data that is written into it. Its size is around 1KB.…
ajay bidari
  • 693
  • 2
  • 10
  • 22