User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:fflush

fflush

    int fflush(FILE *stream);

Flushes stream stream and returns zero on success or EOF on error. Effect undefined for input stream. fflush(NULL) flushes all output streams.

C Sourcecode Example

/* 
 * fflush example code
 * http://code-reference.com/c/stdio.h/fflush 
 */
 
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
#define MAX 80
int main( void )
{
  FILE *filestream = fopen("test.txt", "rt+");
  char buffer[MAX];
  if (filestream)
  {
    fputs("write this in a file", filestream);
    fflush(filestream); /* uncomment this function to see what's happend */
    fgets(buffer, MAX, filestream);
    puts(buffer);
    fclose(filestream);
  }
  return 0;
}

test.txt

file test.txt

Line 1
#Line2
Line 3
#Line 4 
Line 

fflush output

  output: ./fflush

test.txt after running the programm

write this in a file
#Line 4 
Line 5

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/fflush.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz