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.

vsprintf.<br />

Certain compiler options may affect how standard I/O performs. In an effort to<br />

provide<br />

a more tailored version of the formatted I/O routines, the tool chain may convert<br />

a call<br />

to a printfor scanfstyle function to a different call. The options are summarized<br />

below:<br />

•The -msmart-iooption, when enabled, will attempt to convert printf,<br />

scanfand other functions that use the input output formats to an integer only<br />

variant. The functionality is the same as that of the C standard forms, minus the<br />

support for floating point output. -msmart-io=0disables this feature and no<br />

conversion will take place. -msmart-io=1or -msmart-io(the default) will<br />

convert a function call if it can be proven that an I/O function will never be<br />

presented with a floating point conversion. -msmart-io=2is more optimistic than<br />

the default and will assume that non-constant format strings or otherwise<br />

unknown format strings will not contain a floating-point format. In the event<br />

that<br />

-msmart-io=2is used with a floating-point format, the format letter will appear<br />

as literal text and its corresponding argument will not be consumed.<br />

• -fno-short-doublewill cause the compiler to generate calls to formatted I/O<br />

routines that support doubleas if it were a long doubletype.<br />

Mixing modules compiled with these options may result in a larger executable<br />

size, or<br />

incorrect execution if large and small double-sized data is shared across<br />

modules.<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

Ví dụ: / * Chương trình này sẽ cố gắng để viết một tập tin đó là * /<br />

/ * Chỉ đọc. Điều này làm cho chỉ số lỗi để * /<br />

/ * Được thiết lập. Chức năng ferror được sử dụng để kiểm tra * /<br />

/ * Chỉ số lỗi. Chức năng clearerr là * /<br />

/ * Sử dụng để thiết lập lại các errorindicator vì vậy tiếp theo * /<br />

/ * Thời gian ferror được gọi là nó sẽ không báo cáo * /<br />

/ * Lỗi. * /<br />

# include / * Cho 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 ("Không thể mở tập tin \ n");<br />

khác<br />

{<br />

fprintf (myfile, "dòng Writethis đến"<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 />

DS51456B-page 226<br />

FILE<br />

2004 Microchip Technology Inc.<br />

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

khác<br />

Description: Stores information for a file stream.<br />

Include: <br />

fpos_t<br />

Description: Type of a variable used to store a file position.<br />

Include: <br />

size_t<br />

Description: The result type of the sizeofoperator.<br />

Include: <br />

_IOFBF<br />

Description: Indicates full buffering.<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 />

dsPIC<br />

®<br />

Thư viện Công cụ Ngôn ngữ<br />

Include: <br />

Remarks: Used by the function setvbuf.<br />

DS51456B trang 230<br />

2004 Microchip Technology Inc

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

Saved successfully!

Ooh no, something went wrong!