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.

Output:<br />

File renamed<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

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

rewind<br />

Description: Resets the file pointer to the beginning of the file.<br />

Include: <br />

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

Argument: stream stream to reset the file pointer<br />

Remarks: The function calls fseek(stream, 0L, SEEK_SET)and then clears<br />

the error indicator for the given stream.<br />

Example: #include /* for rewind, fopen, */<br />

/* fscanf, fclose, */<br />

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

/* FILE, NULL */<br />

int main(void)<br />

{<br />

FILE *myfile;<br />

char s[] = "cookies";<br />

int x = 10;<br />

if ((myfile = fopen("afile", "w+")) == NULL)<br />

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

else<br />

{<br />

fprintf(myfile, "%d %s", x, s);<br />

printf("I have %d %s.\n", x, s);<br />

/* set pointer tobeginning of file */<br />

rewind(myfile);<br />

fscanf(myfile, "%d %s", &x, &s);<br />

printf("I ate %d %s.\n", x, s);<br />

fclose(myfile);<br />

}<br />

}<br />

Output:<br />

I have 10 cookies.<br />

I ate 10 cookies.<br />

Standard C Libraries with Math Functions<br />

Đầu ra:<br />

Nhập số yêu thích của bạn, thư yêu thích,<br />

Màu sắc yêu thích, lương mong muốn và SSN:<br />

Số mục quét = 5<br />

Số yêu thích = 5, thư yêu thích = T<br />

Màu sắc ưa thích = Green, lương mong muốn = $ 300.000,00<br />

Số An Sinh Xã Hội = 123-45-6789<br />

scanf (Tiếp theo)<br />

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

2004 Microchip Technology Inc DS51456B trang 261<br />

setbuf<br />

Mô tả: Xác định như thế nào một dòng là đệm.<br />

Bao gồm:<br />

Prototype: void setbuf (FILE * stream, char * buf);<br />

Đối số: dòng con trỏ đến dòng mở<br />

buf sử dụng cấp phát bộ đệm<br />

Bình luận: setbufmust được gọi sau khi fopenbut trước khi gọi chức năng khác<br />

hoạt động trên dòng suối. Nếu bufis một con trỏ null, setbufcalls các<br />

chức năng setvbuf (dòng, 0, _IONBF, BUFSIZ) không có đệm;<br />

nếu không setbufcalls setvbuf (dòng, buf, _IOFBF,<br />

BUFSIZ) để đệm đầy đủ với một bộ đệm có kích thước BUFSIZ. Xem setvbuf.<br />

Ví dụ: # include / * Cho setbuf, printf, * /<br />

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

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

int main (void)<br />

{<br />

FILE * myfile1, * myfile2;<br />

char buf [BUFSIZ];<br />

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

{<br />

setbuf (myfile1, NULL);<br />

printf ("myfile1 không có đệm \ n");<br />

fclose (myfile1);<br />

}<br />

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

{<br />

setbuf (myfile2, buf);<br />

printf ("myfile2 có đầy đủ đệm");<br />

fclose (myfile2);

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

Saved successfully!

Ooh no, something went wrong!