#include <stdio.h>
|
|
int
fflush (FILE *stream); |
If the stream argument is NULL, fflush flushes all open output streams.
/****************** this program shows flushing user space buffered data using fflush **************/
#include <stdio.h>
int main()
{
FILE *fp;
int retval = 0;
char name[20] = "c:\\flush1.txt";
fp = fopen(name, "w+");
if(fp == NULL)
{
printf("Error : File open");
return -1;
}
setvbuf(fp, NULL, _IOFBF, 100); // set to full buffering with NULL buffer
fprintf(fp, "we are trying to buffer 100 characters at once with NULL buffer.");
retval = fflush(fp);
if (retval)
{
printf("fflush failed\n");
fclose(fp);
unlink(name);
return -1;
}
else printf("Buffer successfully flushed\n");
fclose(fp);
unlink(name);
return 0;
}
Output
we are trying to buffer 100 characters at once with NULL buffer.
Buffer successfully flushed
| [EBADF] | |
| The stream argument is not an open stream, or, in the case of fflush, not a stream open for writing. | |
The function fflush may also fail and set errno for any of the errors specified for the routine write.
|
© 2005-2007 Nokia |