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.

*pos<br />

if successful; otherwise, fsetpossets errno.<br />

fseek (Continued)<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

printf ("10,0 /% d =% f \ n", x + 1, nums [x]);<br />

}<br />

numwrote = fwrite (nums, sizeof (double),<br />

10, buf);<br />

printf ("đã viết% dnumbers \ n \ n", numwrote);<br />

fclose (buf);<br />

DS51456B-page 246<br />

2004 Microchip Technology Inc.<br />

}<br />

Example: /* This program opens a file and reads bytes at */<br />

/* several different locations. The fgetpos */<br />

/* function notes the 8th byte. 21 bytes are */<br />

/* read then 18 bytes are read. Next the */<br />

/* fsetpos function is set based on the */<br />

/* fgetpos position and theprevious 21 bytes */<br />

/* are reread. */<br />

#include /* for fgetpos, fread, */<br />

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

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

/* fpos_t, sizeof */<br />

int main(void)<br />

{<br />

FILE *myfile;<br />

fpos_t pos;<br />

char buf[25];<br />

if ((myfile = fopen("sampfgetpos.c", "rb")) ==<br />

NULL)<br />

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

else<br />

{<br />

fread(buf, sizeof(char), 8, myfile);<br />

if (fgetpos(myfile, &pos) != 0)<br />

perror("fgetpos error");<br />

else<br />

{<br />

fread(buf, sizeof(char), 21, myfile);<br />

printf("Bytes read: %.21s\n", buf);<br />

fread(buf, sizeof(char), 18, myfile);<br />

printf("Bytes read: %.18s\n", buf);<br />

}<br />

if (fsetpos(myfile, &pos) != 0)<br />

khác<br />

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

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

2004 Microchip Technology Inc DS51456B trang 249<br />

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

{<br />

numread = fread (readnums, sizeof (double),<br />

10, buf);<br />

printf ("Đọc% số d \ n", numread);<br />

for (x = 0; x

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

Saved successfully!

Ooh no, something went wrong!