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

c - fflush or buffer clean

I'm using the following code, and when I'm picking 's' for an example, the inner function runs and Im using scanf("%d") in the inner function and the spacebar or the enter that comes after the last input is saved for the next ch in the main. I've…
0
votes
0 answers

How can i handle invalid input to cin(cpp)

when i use the code below, char command; cin >> command; i want to get only ('a','c','d') as inputs. In other alphabet(int) cases, i can solve the problem using 'switch statement' But when someone types multiple characters, my program doesn't know…
gun bos
  • 51
  • 4
0
votes
4 answers

Problem reading two strings with getchar() and then printing those strings in C

This is my code for two functions in C: // Begin void readTrain(Train_t *train){ printf("Name des Zugs:"); char name[STR]; getlinee(name, STR); strcpy(train->name, name); printf("Name des Drivers:"); char…
John B
  • 23
  • 3
0
votes
1 answer

How to use ffllush(stdout) in c?

I know about fflush(stdin) that it is undefined behavior according to standard. But when it comes to stdout, there is no such restriction. I did google to get the concept of using stdout as a parameter of fflush, but I couldn't get it. Can someone…
Abhishek Jaiswal
  • 288
  • 2
  • 14
0
votes
0 answers

fprintf causing MemFree to decrease

I have a thread logging variables' values to a file, something similar to this: fp = fopen("log.txt", "a"); fprintf(fp, "%d,", var1); fprintf(fp, "%d,", var2); fprintf(fp, "%d,", var3); ... fprintf(fp, "\n"); fclose(fp); I noticed that MemFree in…
godo
  • 195
  • 1
  • 11
0
votes
1 answer

Using fflush for speeding up code to prevent a time limit exceeded

The following code gets TLE (time limit exceeded) if the standard output is not flushed. #include int main(){ int a; while(1){ scanf("%d",&a); printf("%d\n",a); fflush(stdout); if(a==42) …
Imtiaz
  • 25
  • 2
  • 7
0
votes
1 answer

scanf for reading float numbers doesn't work as expected

I am in a programming class since 2 weeks and have some trouble with scanning keyboard input an assigning it to a variable in C. #include #include int main() { float creditSum, interestRate, repayment; system("clear"); …
vrms
  • 217
  • 2
  • 8
0
votes
1 answer

abrupt end of program while fflush in c

So I was doing an assignment for a class in which I have to perform basic array functions for an array of structures and in taking input my program closed on its own. The program terminated after taking input of name void input(struct record…
0
votes
1 answer

How to use fflush(stdin) in C++

I have a simple question (I think so) about fflush() in C++. Every time I write some code to input string in C++, I have to try many many ways because My program caused Error every time. So I will ask a very simple question. My code here: void…
0
votes
0 answers

libcurl inserts additional data to download files

I use libcurl in my C code to download files given their urls. My code looks similar to this: #include #include #include static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { size_t…
AnhHao Trần
  • 145
  • 1
  • 10
0
votes
1 answer

How do I check if the previous 2 getchars were a space?

My code reads a textfile or input from the terminal and prints out the message but with each word on a new line the code below works with the exception of double or more spaces. Because I use the space as an indication that a whole word has ended.…
0
votes
1 answer

fflush() is not workign as expected

I am currently working on a project that I need file io. In this project I am often reading and writing to a file. But the thing is that I am failing to read anything in from the file. I have tried using fflush() but that does not seem to be…
Joe
  • 13
  • 2
0
votes
2 answers

Is file_get_contents & file_put_contents reliable or can lead to loss of data? Benchmark results

I was wondering what happens if multiple scripts are sharing same file. I uploaded the test on remote server, where they use HDD to store data. There were 7 tests total, but the family of 6 are compatible. I have 7 files of different size which I…
Johny Bony
  • 375
  • 2
  • 9
0
votes
1 answer

How to flush output when using inplace editing with awk?

I want to use awk to edit a column of a large file inplace. If, for any reason, the process break/stops, I don't want to lose the work already done. I've tried to add fflush but seems it does not wort with inplace. In order to simulate the desired…
LEo
  • 477
  • 5
  • 14
0
votes
2 answers

fprintf() to stdout not working after creating and opening a FIFO

When my program starts, it just creates a fifo and opens it, after that I just want to output some information to the screen, however, nothing gets printed out. Here's a snippet of my code: void listen(const server_config_t* server_conf) { //…
136
  • 1,083
  • 1
  • 7
  • 14