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

Is this the proper way to flush the C input stream?

Well I been doing a lot of searching on google and on here about how to flush the input stream properly. All I hear is mixed arguments about how fflush() is undefined for the input stream, and some say just do it that way, and others just say don't…
3
votes
4 answers

fflush(stdout) in c

Right when I am at fflush(stdout) and I break there in GDB, can I know what is there in stdout before I actually print it? How can I know what is there in stdout at any point in time?
hari
  • 9,439
  • 27
  • 76
  • 110
3
votes
1 answer

Calling fflush inside multithreaded signal handler?

I have a basic sketch of implementing a multithreaded web proxy: FILE *proxy_log_file; static void SIGUSR1_handler(int sig) { (void)sig; fflush(proxy_log_file); } int main(int argc, char **argv) { proxy_log_file = fopen("proxy.log",…
user6269144
  • 318
  • 1
  • 10
3
votes
1 answer

Using many calls to fprintf; when should I use fflush?

I have a simple little program that converts one filetype to another. There are quite a few calls to fprintf() (roughly linearly dependent to the size of the file to convert). When I started, there were no calls to fflush(). On small files (<10 Kb)…
Marco Merlini
  • 875
  • 7
  • 29
2
votes
4 answers

Is there a way to compare multiple strings in C? [ I input them through fgets() ]

int Distance() { char from[40], to[40]; double val; double result; printf("Enter what you want to convert from: "); fflush(stdin); fgets(from, 40, stdin); printf("Enter what you want to convert to: \n"); …
2
votes
1 answer

fflush(NULL) and POSIX compliance

TL;DR: Is it posixly incorrect for fflush(NULL) not to flush stdin? Consider the following code snippet, #include #include #include int main(void) { char line[128] = {0}; fgets(line, sizeof(line), stdin); …
SuibianP
  • 99
  • 1
  • 11
2
votes
1 answer

why the execution order of output is not as expected

I'm learning c and I got stuck in some codes as below from a tutorial. #include int main() { fprintf(stdout, "This is to stdout. "); fprintf(stderr, "This is to stderr. "); fprintf(stdout, "This is also to stdout. "); } and…
o o
  • 145
  • 6
2
votes
1 answer

why does printf output normally without fflush

I learned that stdout is line buffered, and buffer is automatically flushed under several circumstances (1) when the buffer is full, (2) when print a \n character and the output is going to a "terminal" (e.g. is not being redirected to a file), (3)…
codesavesworld
  • 587
  • 3
  • 10
2
votes
1 answer

fflush() always returns 0 but sets errno to 11 (resource temporarily unavailable)

Whenever I call the vasprintf() function errno gets set to 11 (resource temporarily unavailable). However, it appears that everything is functioning correctly. To better understand the source of the error I found an implementation of vasprintf() in…
EricB
  • 468
  • 3
  • 9
2
votes
0 answers

No need of fflush(stdout) with printf in C?

Until now, I used fflush(stdout) when using printf without \n, since we have to flush the buffer. But I found that the below code also works fine. #include int main(void){ printf("hello world"); // without fflush(stdout) } //…
jwkoo
  • 2,393
  • 5
  • 22
  • 35
2
votes
1 answer

How to read QProcess output

In the main thread of a Gui Application I am starting a QProcess of another GUI application that will log some messages over time in stdout using fputs(). The problem is that after some time the GUI application started with QProcess will freeze…
2
votes
1 answer

How do I limit the input of scanf to integers and floats (numbers in general)

I am curently learning C Programming in University and I got the task to write a program witch puts out the interception points with 0 / x-axis of any function ax^2+bx+c. In order to make sure that the input is correct (int, float, etc.) I run the…
2
votes
1 answer

How to know when a buffer flush is needed?

Considering two functions that flush buffers: fflush() sync() How can I know when a call to either one is needed? I know adding a '\n' to printf() will flush the output buffer, but if the string contains no such character, when can I skip this…
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
2
votes
0 answers

when stdout is redirected to a file fflush is not enough

I have a C program with 9 calls to printf and I need it to run on a remote server for several days. So I decided to redirect the stdout to a file to check the progresses: FILE *foutput=freopen("output.txt","w",stdout); After some debugging I found…
GRquanti
  • 527
  • 8
  • 23
2
votes
2 answers

C++ - Why fflush(stdout) does not work with iostream?

I was reading about freopen() and realized that if we specify stdin/stdout to it, the function will work even if we code using cin/cout. Researching a little bit, I had found this link freopen() equivalent for c++ streams, where one of the users…
Enzo Nakamura
  • 127
  • 1
  • 9
1 2
3
13 14