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

SCANF probably not reading the correct value

If you enter more than five characters in the "name" field the function giving the wrong output, otherwise if the input is less than or equal to five characters the function works just fine, or if I use just %s instead of reading five characters…
arka
  • 418
  • 2
  • 9
-1
votes
2 answers

C program skipping printf and scanf statements

My program below conducts a Caesar's cipher in C. For some reason, after a message has been input by the user, the printf(" \nEnter key:") and scanf("%d", &key) statements get "jumped" over. My thought was something related to the input buffer…
ddisec
  • 71
  • 1
  • 6
-1
votes
1 answer

Why is the last printf() not printing?

I trying to create something where the user has to give certain numbers and at the end the program prints all the numbers with a space in between. Everything is working, except the last printf(). I have tried to fflush in and out like the previous…
MatsAZ456
  • 29
  • 5
-1
votes
1 answer

How is the working of fflush(stdin) changing the output in below code?

#include int main() { int test_no ,count=1,i,n,j; scanf("%d",&test_no); fflush(stdin); int arr1[test_no]; for(i=0;i
-1
votes
2 answers

Remove new line character from console

I have this loop, but when i hit enter after my character, it processes it and then processes the '\n' before asking for input again. Please!!!! Help int input; while (true){ input = getchar(); fflush(NULL); input =…
i_use_the_internet
  • 604
  • 1
  • 9
  • 28
-1
votes
1 answer

How can I stop the program inside the a parent or a child process?

I have this piece of code that I developed just to address a problem that I have in another large program that I am developing. #include #include #include #include #include #include…
Pro
  • 173
  • 4
  • 15
-1
votes
2 answers

What is same as fflush function in Linux?

Linux manual recommends that the fflush function should not be used. So, I found that while( getchar() != '\n' plays the same role as fflush(stdin). e.g.) my trial code: #include void main(void) { char input[100] = {}; …
Danny_Kim
  • 299
  • 2
  • 18
-1
votes
2 answers

Whenever I am executing the program, it is taking an undesired extra input at the last

#include int main() { int i; char name[3]; float price[3]; int pages[3]; printf("Enter names, price and no of pages of 3 books:\n "); fflush(stdin); for(i=0;i<=2;i++) scanf("…
-1
votes
2 answers

Why does printf not work in my program (Tried flushing)

I learned Objective-C before C and now that I am going back to C, I don't understand why the printf() inside the loops does not work? Could someone advise me? The program is the first challenge in the book "Programming Challenges" By Skiena and…
Jurko Guba
  • 630
  • 7
  • 17
-2
votes
1 answer

Program seems to skip getchar()

So I'm new to coding in C and coding in general. I'm learning with a book and a code in there just won't work and I don't know why. It's probably a trivial matter but as I said..I'm a bloody noob. Anyway this is the code: #include void…
-2
votes
1 answer

Why the loop "scanf" method dead circle in objective-c lanuguage?

I write a small console program in objective-c. It need to use the scanf method to receive the number.When I enter a character, it will make a mistake.So I try to solve it,but it has entered a cycle of death! See the following code, to help me solve…
fly_basket
  • 49
  • 7
-2
votes
2 answers

write output to a specific file in C

My program executes with two arguments (put in argv) like below: $ myProgram input output How do I redirect all printf(..) to the output file? I saw some suggestion about using fflush(stdout) but I haven't used it before. Could anyone please show…
Toan Le
  • 412
  • 1
  • 6
  • 17
-3
votes
2 answers

What is fflush exactly and what does it do?

I was reading http://www.cplusplus.com/reference/cstdio/fflush/ and I was curious about what it means. According to the website it says: If the given stream was open for writing (or if it was open for updating and the last i/o operation was an…
Storm
  • 17
  • 3
-3
votes
1 answer

fwrite() and file corruption

I'm trying to write a wchar array to a file in C, however there is some sort of corruption and unrelevant data like variables and paths like this c.:.\.p.r.o.g.r.a.m. .f.i.l.e.s.\.m.i.c.r.o.s.o.f.t. .v.i.s.u.a.l. .s.t.u.d.i.o.…
ᴘᴀɴᴀʏɪᴏᴛɪs
  • 7,169
  • 9
  • 50
  • 81
-4
votes
1 answer

limited input from user in struct

help please this doesnt work properly input omayma.firstname : AAAAAAAAAAAAAAAAAAAAAAAAAAA omayma.lastname : BBBBBBBBBBBBBBBBBBBBBBBBBBBB output : omayma.firstname : AAAAAAAAAABBBBBBBBBB omayma.lastname : BBBBBBBBBB expected output :…
Omayma Benali
  • 119
  • 1
  • 7
1 2 3
13
14