30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Include: <br />

Prototype: void clearerr(FILE *stream);<br />

Argument: streamstream to reset error indicators<br />

Remarks: The function clears the end-of-file and error indicators for the given<br />

stream (i.e., feofand ferrorwill return false after the function<br />

clearerris called.)<br />

Example: /* This program tries to write to a file that is */<br />

/* readonly. This causes the error indicator to */<br />

/* be set. The function ferror is used to check */<br />

/* the error indicator. The function clearerr is */<br />

/* used to reset the errorindicator so the next */<br />

/* time ferror is called it will not report an */<br />

/* error. */<br />

#include /* for ferror, clearerr, */<br />

/* printf, fprintf, fopen,*/<br />

/* fclose, FILE, NULL */<br />

int main(void)<br />

{<br />

FILE *myfile;<br />

if ((myfile = fopen("sampclearerr.c", "r")) ==<br />

NULL)<br />

printf("Cannot open file\n");<br />

else<br />

{<br />

fprintf(myfile, "Writethis line to the "<br />

"file.\n");<br />

if (ferror(myfile))<br />

printf("Error\n");<br />

else<br />

printf("No error\n");<br />

clearerr(myfile);<br />

if (ferror(myfile))<br />

printf("Still has Error\n");<br />

else<br />

printf("Error indicator reset\n");<br />

fclose(myfile);<br />

}<br />

}<br />

Output:<br />

/ * Chỉ số lỗi và tìm ra lỗi. Các * /<br />

/ * Chức năng clearerr được sử dụng để thiết lập lại các lỗi * /<br />

/ * Chỉ nên thời gian ferror tiếp theo được gọi là * /<br />

/ * Nó sẽ không báo lỗi. * /<br />

# include / * Cho ferror, clearerr, * /<br />

/ * Printf, fprintf, * /<br />

/ * Fopen, fclose, * /<br />

/ * FILE, NULL * /<br />

int main (void)<br />

{<br />

FILE * myfile;<br />

if ((myfile = fopen ("sampclearerr.c", "r")) ==<br />

NULL)<br />

printf ("Không thể mở tập tin \ n");<br />

khác<br />

{<br />

fprintf (myfile, "Viết dòng này cho"<br />

"Tập tin. \ N");<br />

if (ferror (myfile))<br />

printf ("Lỗi \ n");<br />

khác<br />

printf ("Không có lỗi \ n");<br />

clearerr (myfile);<br />

if (ferror (myfile))<br />

printf ("Vẫn có lỗi \ n");<br />

khác<br />

printf ("Lỗi chỉ thiết lập lại \ n");<br />

fclose (myfile);<br />

}<br />

}<br />

Đầu ra:<br />

Lỗi<br />

Lỗi chỉ thiết lập lại<br />

Thư viện chuẩn C với hàm toán học<br />

2004 Microchip Technology Inc DS51456B trang 233<br />

fflush<br />

Mô tả: bừng bộ đệm trong dòng quy định.<br />

Bao gồm:<br />

Nguyên mẫu: int fflush (FILE * stream);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!