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
2
votes
1 answer

fflush or sync need after boost::filesystem::copy?

I have a problem when using boot library for copying files. After copying a file, sometimes the file size if 0kb. Here is my code: boost::filesystem::copy("from.txt", "to.txt"); I just want to know whether should I call sync(), fsync(), or …
2
votes
1 answer

fflush behavior change in glibc 2.23

As of 2.23 the glibc seems to have changed its behavior on an fflush of a stream created with fmemopen, in that it resets the position to 0. I saw in the change-log that a the implementation of fmemopen was updated to fix a bunch of bugs, but none…
zippy
  • 1,228
  • 10
  • 19
2
votes
1 answer

How remove displayed text from stdout?

I have created a macro that display a text and after that it flush stdout. The problems is how to force to clear old printed text if the text is more longer than the newer. Example : If I try to print a string with 50 characters after that I need to…
developer
  • 4,744
  • 7
  • 40
  • 55
2
votes
5 answers

the use of fflush(FILE* stream)

I Really can't understand the use of the : fflush() function , could I find a good implementation of this function ? I read some resources about it but I still can't grasp it well , actually I want to know what this function really do ?
Michael Heidelberg
  • 993
  • 11
  • 24
2
votes
3 answers

Checking whether the input is a whole number

I need to make a function that gets input from the user and makes sure that it is a whole number and does not contain any character. I wrote this code which works perfectly for integers and for single characters. But it terminates if I enter dfd…
Joey Pinto
  • 1,735
  • 1
  • 18
  • 34
2
votes
2 answers

Is fflush safe to be called from a signal handler?

Well, title says most of it. Say my application is logging to stdout/file. However, when terminated it is not always completely flushed. One solution would be to flush after each logging action, however that slowed the program down unacceptably. So,…
heinrich5991
  • 2,694
  • 1
  • 19
  • 26
2
votes
1 answer

Using fwrite without calling fflush or writing to stderr first

I have a function which writes binary data to a file or stdout. However the call to fwrite() sometimes fails, UNLESS I fflush(stderr) or print a report to stderr before attempting to fwrite. Is this normal behaviour, or indicative of some underlying…
JWDN
  • 382
  • 3
  • 13
2
votes
2 answers

fflush(stdin) ANSI C

I am a beginner in ANSI C, and I have a question, it may be silly question and I am sorry for it. #include main() { int age; printf("Hello World!\n"); printf("Please enter your age: "); …
Mahmoud Emam
  • 1,499
  • 4
  • 20
  • 37
1
vote
2 answers

The screen print is confusing ?

my code is : #include void main( int argc, char** argv) { printf("%s", argv[0]); system("pwd"); } The output is: [river@localhost studio]$ ./a.out /home/river/Desktop/studio ./a.out[river@localhost studio]$ It seems that…
river
  • 694
  • 6
  • 22
1
vote
0 answers

Function inputElements() taking input only once

I am trying to create a program to find the transpose of a matrix my dynamic memory allocation. However, while entering the elements of the matrix I can't input more than one element, its only taking the a[0][0] as the input and the program is…
1
vote
1 answer

No output in the parent process without fflush(stdout)

I'm trying to understand what is behind this behaviour in my parent process. Basically, I create a child process and connect its stdout to my pipe. The parent process continuously reads from the pipe and does some stuff. I noticed that when…
Pol
  • 185
  • 9
1
vote
1 answer

Overflow with scanf, even using fflush and input length limitation

I am a beginner in C and am currently going through the book "C: Einfuehrung und professionelle Anwendung" by Mr. Prinz. The example from the book below should show how to limit the input using scanf and to flush the buffer in between in order to…
jupiter_jazz
  • 333
  • 2
  • 8
1
vote
1 answer

Automatic file buffer flushing when file opened by another program *only if* other program not already running (macOS)

I've run into a weird behavior on macOS that I started investigating due to an accidental race condition that would occur when telling the OS to open an RTF file I'd just processed, but hadn't closed or explicitly flushed. If the file handler (Word,…
torstenvl
  • 779
  • 7
  • 16
1
vote
2 answers

Read multiple strings and float with multiple cases in C

My main problem here is that I have two strings and a float to read. The strings' size is 10 bytes, but I should be able to read no matter what input it is and store it inside the strings. For example: if my input is Hello world! then the string…
1
vote
1 answer

not getting expected output from fgets() after fflush()

Here is the simple code after fflush() we are not getting the expected output. We expect "Hello World file2" but it is showing some random garbage value as mentioned below. FILE 2 b4 = output_reg : P\ufffd\ufffdr\ufffd FILE 2 af = output_reg :…