30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Error indicator reset<br />

Standard C Libraries with Math Functions<br />

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

fflush<br />

Description: Flushes the buffer in the specified stream.<br />

Include: <br />

Prototype: int fflush(FILE *stream);<br />

Argument: stream pointer to the stream to flush.<br />

Return Value: Returns EOF if a write error occurs; otherwise, returns zero for<br />

success.<br />

Remarks: If stream is a null pointer, all output buffers are written to files. fflush<br />

has no effect on an unbuffered stream.<br />

fgetc<br />

Description: Get a character from a stream<br />

Include: <br />

Prototype: int fgetc(FILE *stream);<br />

Argument: stream pointer to the open stream<br />

Return Value: Returns the character read or EOF if a read error occurs or end of<br />

file is<br />

reached.<br />

Remarks: The function reads the next character from the input stream, advances<br />

the file-position indicator and returns the character as an unsigned<br />

charconverted to an int.<br />

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

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

/* NULL, EOF */<br />

int main(void)<br />

{<br />

FILE *buf;<br />

char y;<br />

if ((buf = fopen("afile.txt", "r")) == NULL)<br />

chỉ số lỗi, nội dung mảng là không xác định.<br />

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

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

/ * FILE, NULL * /<br />

# define MAX 50<br />

int main (void)<br />

{<br />

FILE * buf;<br />

char s [MAX];<br />

if ((buf = fopen ("afile.txt", "r")) == NULL)<br />

printf ("Không thể mở afile.txt \ n");<br />

khác<br />

{<br />

trong khi (fgets (s, MAX, buf) = NULL)<br />

{<br />

printf ("% s |", s);<br />

}<br />

fclose (buf);<br />

}<br />

}<br />

Đầu vào:<br />

Nội dung afile.txt (được sử dụng như đầu vào):<br />

Ngắn<br />

Chuỗi dài hơn<br />

Đầu ra:<br />

Ngắn<br />

| Chuỗi dài hơn<br />

|<br />

dsPIC<br />

®<br />

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

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

else<br />

{<br />

y = fgetc(buf);<br />

DS51456B trang 236<br />

fopen<br />

Mô tả: Mở một tập tin.<br />

Bao gồm:<br />

2004 Microchip Technology Inc<br />

while (y != EOF)<br />

{<br />

printf("%c|", y);<br />

y = fgetc(buf);<br />

Prototype: FILE * fopen (const char * filename, const char * mode);<br />

Tên tên tập tin của tập tin: đối số<br />

loại phương thức truy cập được phép<br />

Quay trở lại giá trị: Trả về một con trỏ đến dòng mở. Nếu chức năng không mộ<br />

con trỏ null

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

Saved successfully!

Ooh no, something went wrong!