This shows you the differences between two versions of the page.
— |
c:stdio.h:fflush [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ===== fflush ===== | ||
+ | <code c> | ||
+ | int fflush(FILE *stream); | ||
+ | </code> | ||
+ | |||
+ | 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 ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * 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; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | === test.txt === | ||
+ | file test.txt | ||
+ | <code c> | ||
+ | Line 1 | ||
+ | #Line2 | ||
+ | Line 3 | ||
+ | #Line 4 | ||
+ | Line | ||
+ | </code> | ||
+ | |||
+ | ==== fflush output ==== | ||
+ | output: ./fflush | ||
+ | |||
+ | test.txt after running the programm | ||
+ | <code c> | ||
+ | write this in a file | ||
+ | #Line 4 | ||
+ | Line 5 | ||
+ | </code> |