[Hàm trong C] hàm fflush

cacodemon1812

New member
Xu
0
Hàm fflush
Khai báo :
Mã:
int fflush(FILE *stream);
Hàm dùng làm sạch vùng đệm của tệp . Nếu thành công hàm cho giá trị 0 , trái lại hàm trả về EOF


Code:
Mã:
#include <string.h> 
#include <stdio.h> 
#include <conio.h> 
#include <io.h> 
void flush(FILE *stream); 
int main(void) 
{ 
FILE *stream; 
char msg[] = "This is a test"; 
/* tao 1 tep */ 
stream = fopen("DUMMY.FIL", "w"); 
/*ghi mot vai du lieu len tep */ 
fwrite(msg, strlen(msg), 1, stream); 
clrscr(); 
printf("Press any key to flush DUMMY.FIL:"); 
getch(); 
flush(stream); 
printf("\nFile was flushed, Press any key to quit:"); 
getch(); 
return 0; 
} 
void flush(FILE *stream) 
{ 
int duphandle; 
/* lam sach vung dem */ 
fflush(stream);
duphandle = dup(fileno(stream)); 
close(duphandle); 
}

Nguồn: Sưu tầm
 

Trending content

VnKienthuc lúc này

Không có thành viên trực tuyến.

Định hướng

Diễn đàn VnKienthuc.com là nơi thảo luận và chia sẻ về mọi kiến thức hữu ích trong học tập và cuộc sống, khởi nghiệp, kinh doanh,...
Top