is there another way to PAUSE the command prompt without using
??!!Code:system(PAUSE);
is there another way to PAUSE the command prompt without using
??!!Code:system(PAUSE);
faq.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
but there is a simple questions --->
what fflush() really do ??
i read that it :
fflush() causes any unwritten data for that stream to be written to the file
fflush() function causes any buffered output data for stream to be written to file
but i don`t understand what buffered mean here !!
what`s the buffered output data
ex:
FILE *fp = fopen("file.txt","rw");
fflush(fp);
is this meaningfull ??
and there is something called flush()
is it the same with fflush()
i know i ask many question but i want to learn that`s all ..
When you work with a file, the data that you write to the file is first stored in a memmory 'buffer'. When this buffer gets full, or when you tell the program to flush the buffer, then any data in the buffer gets writen to the harddisk or wherever the file is actually located.Originally Posted by Meshal
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
ammm , so why this program doesn`t do as you say ?Originally Posted by King Mir
after opening the file file.txt i see nothing ?! whyCode:main() { FILE *fp = fopen("file.txt","r+w"); //file.txt empty file! printf("this will be printed to the file"); fflush(fp); }
No, it will be printed to stdout. UseOriginally Posted by Meshal
instead.Code:fprintf(fp, "this will be printed to the file");
can use getchar() as wellOriginally Posted by Meshal
ssharish2005
till now i don`t know why we need fflush() and how we use it in the program
There is at least one level of indirection from raw input from hardware to your output device (perhaps a screen). The memory where this input is stored needs to be flushed as it fills up with data, so that you don't run into a situation where the memory is full and you miss something, or worse, can't accept new input. Now, in C's standard implementation, the OS will typically make an educated guess, flushing this memory if it recieves a newline and whatever data it contained is written to the output device.
Now if you neglect to include a newline with your output or the system doesn't flush when you expect it to, you need to do it yourself, hence, fflush(FILE*).
fflush only works with output streams (like files opened with "w" and stdout) and not input streams (like stdin). This is chiefly because writing to an input stream does not make any sense. Can you write to a keyboard? How about a mouse? Input devices "read things" or report events only, and have no business doing any "writing," as far as I know.
understood , and i need to know about system more
i`ll buy then (Advanced Unix Programming) to learn more about this stuff !
thanks for your help and explain to fflush ,
but there is still a question hasn`t been answered !!!!!!!!!!
=========================
and there is something called flush()
is it the same with fflush()
=========================
> and there is something called flush()
Not in standard C.