Fflush

Fflush

fflush is a C function belonging to the ANSI C standard library, and included in the file stdio.h. Its purpose is to write any buffered output data for the specified stream.

Function prototype

:int fflush(FILE "*stream_pointer");

Argument meaning:
* "stream_pointer" is either a pointer to the output stream for which the buffered data is to be written, or "NULL". If "NULL" is passed as an argument fflush flushes all opened output streams.

Return value

The return value is an "integer" which means:
* "0" (zero) : function performed successfully in the stream.
* "EOF" : an error occurred and errno is set.

Note that each error number has a distinct meaning. The meaning can usually be revealed by checking "errno.h"; the strerror() function converts an error number to a descriptive text string.

Remarks

* The "fflush" function is usually used to prevent data loss by ensuring that the data is written to stream
* It should be used for output streams only; otherwise the behavior is undefined.
* Often "fflush" is used on the standard output stream because stdout is usually buffered and the output might not be prompted immediately.
* A call to fclose will flush the stream.
* A null argument did not have defined behavior in older implementations of the C library.

Example


#include

int main(void) { FILE *file_pointer; int i; file_pointer = fopen("text.txt", "wt"); for (i = 0; i < 100; i++) { fprintf(file_pointer, "Line %d ", i); fflush(file_pointer); } fclose(file_pointer); return 0;}This program code creates a file called "text.txt" and writes 100 strings of the form "Line " to it, flushing the buffer after each write.

External links

* [http://c-faq.com/stdio/stdinflush.html comp.lang.c FAQ list · Question 12.26a]
*

See also

* fclose
* setvbuf


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • Stdio.h — Saltar a navegación, búsqueda stdio.h, que significa standard input output header (cabecera estandar E/S), es la biblioteca estándar del lenguaje de programación C, el archivo de cabecera que contiene las definiciones de macros, las constantes,… …   Wikipedia Español

  • Message Passing Interface — Сюда перенаправляется запрос «OpenMPI». На эту тему нужна отдельная статья. Message Passing Interface (MPI, интерфейс передачи сообщений) программный интерфейс (API) для передачи информации, который позволяет обмениваться сообщениями между… …   Википедия

  • stdio.h — stdio.h, que significa standard input output header (cabecera estandar E/S), es la biblioteca estándar del lenguaje de programación C, el archivo de cabecera que contiene las definiciones de macros, las constantes, las declaraciones de funciones… …   Wikipedia Español

  • Setvbuf — is a function in standard C which lets the programmer control the buffering of a file stream. It is declared in ; its function prototype is:int setvbuf(FILE *stream, char *buf, int mode, size t size); stream is a pointer to the file stream for… …   Wikipedia

  • C file input/output — C Standard Library Data types Character classification Strings Mathematics File input/output Date/time Localiza …   Wikipedia

  • Goertzel algorithm — The Goertzel algorithm is a digital signal processing (DSP) technique for identifying frequency components of a signal, published by Dr. Gerald Goertzel in 1958. While the general Fast Fourier transform (FFT) algorithm computes evenly across the… …   Wikipedia

  • Inetd — is a super server daemon on many Unix systems that manages Internet services. First appearing in 4.3BSD [http://www.freebsd.org/cgi/man.cgi?query=inetd] , it is generally located at /usr/sbin/inetd.FunctionOften called a super server , inetd… …   Wikipedia

  • List of C functions — This page aims to alphabetically list all the predefined functions used in the C standard library, and a few of the non standard functions. * assert.h ** (no functions) * ctype.h ** (non standard) digittoint ** isalnum ** isalpha ** (non… …   Wikipedia

  • Criba de Eratóstenes — Saltar a navegación, búsqueda La criba de Eratóstenes es un algoritmo que permite hallar todos los números primos menores que un número natural dado N. Se forma una tabla con todos los números naturales comprendidos entre 2 y N y se van tachando… …   Wikipedia Español

  • Funciones de la biblioteca estándar de C — Anexo:Funciones de la biblioteca estándar de C Saltar a navegación, búsqueda El propósito de este artículo es proporcionar un listado alfabético de todas las funciones de la biblioteca estándar de C, y unas pocas funciones no estándar. Contenido… …   Wikipedia Español

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”