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.

char buf[256];<br />

if ((myfile1 = fopen("afile1", "w+")) != NULL)<br />

{<br />

if (setvbuf(myfile1, NULL, _IONBF, 0) == 0)<br />

printf("myfile1 has no buffering\n");<br />

else<br />

printf("Unable to define buffer stream "<br />

"and/or size\n");<br />

}<br />

fclose(myfile1);<br />

if ((myfile2 = fopen("afile2", "w+")) != NULL)<br />

{<br />

if (setvbuf(myfile2, buf, _IOFBF, sizeof(buf)) ==<br />

0)<br />

printf("myfile2 has a buffer of %d "<br />

"characters\n", sizeof(buf));<br />

else<br />

printf("Unable to define buffer stream "<br />

"and/or size\n");<br />

}<br />

fclose(myfile2);<br />

}<br />

Output:<br />

myfile1 has no buffering<br />

myfile2 has a bufferof 256 characters<br />

Standard C Libraries with Math Functions<br />

2004 Microchip Technology Inc. DS51456B-page 263<br />

sprintf<br />

Description: Prints formatted text to a string<br />

Include: <br />

Prototype: int sprintf(char *s, const char *format, ...);<br />

Arguments: s storage string for output format format control string<br />

... optional arguments<br />

Return Value: Returns the number of characters stored in sexcluding the<br />

terminating<br />

null character.<br />

Remarks: The format argument has the same syntax and use that it has in<br />

printf.<br />

Example: #include /* for sprintf, printf */<br />

để.<br />

Ví dụ: # include / * Cho tmpnam, L_tmpnam, * /<br />

/ * Printf, NULL * /<br />

int main (void)<br />

{<br />

char * mYfiLEname;<br />

char mybuf [L_tmpnam];<br />

char * myptr = (char *) & mybuf;<br />

if ((mYfiLEname = tmpnam (myptr)) == NULL)<br />

printf ("Không thể tạo tên tập tin tạm thời");<br />

khác<br />

printf ("tạm thời tập tin% s đã được tạo ra",<br />

mYfiLEname);<br />

}<br />

Đầu ra:<br />

Tập tin tạm thời được tạo ra ctm00001.tmp<br />

ungetc<br />

Mô tả: Đẩy nhân vật trở lại vào dòng.<br />

Bao gồm:<br />

Nguyên mẫu: int ungetc (int c, FILE * stream);<br />

Đối số: ký tự c được đẩy lùi<br />

dòng con trỏ đến dòng mở<br />

Quay trở lại giá trị: Trả về nhân vật đẩy nếu thành công; nếu không, trả về EOF<br />

Ghi chú: Các nhân vật bị đẩy trở lại sẽ được trả về bởi sau đó đọc trên<br />

dòng. Nếu có nhiều hơn một nhân vật được đẩy trở lại, họ sẽ có<br />

trở lại theo thứ tự ngược lại đẩy họ. Một cuộc gọi thành công vào một tập tin<br />

chức năng định vị (fseek, fsetposor quay lại) hủy bỏ bất kỳ đẩy<br />

ký tự trở lại. Chỉ có một nhân vật của pushback được đảm bảo.<br />

Nhiều cuộc gọi đến ungetcwithout một vị trí can thiệp đọc hoặc tập tin<br />

hoạt động có thể gây ra một sự thất bại.<br />

dsPIC<br />

®<br />

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

DS51456B trang 266 2004 Microchip Technology Inc<br />

Ví dụ: # include / * Cho ungetc, fgetc, * /<br />

/ * Printf, fopen, fclose, * /<br />

/ * FILE, NULL, kết thúc tập tin * /<br />

int main (void)<br />

{

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

Saved successfully!

Ooh no, something went wrong!