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.

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

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

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

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

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

printf("%d\n", x);<br />

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

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

fscanf(myfile, "%c", a);<br />

printf("%c\n", a);<br />

fclose(myfile);<br />

}<br />

}<br />

Input:<br />

Contents of afile:<br />

Print this string 100 times<br />

Output:<br />

Print<br />

this<br />

string<br />

100<br />

times<br />

fscanf (Continued)<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

DS51456B-page 244<br />

fseek<br />

2004 Microchip Technology Inc.<br />

Description: Moves file pointer to a specific location.<br />

Include: <br />

Prototype: int fseek(FILE *stream, long offset, int mode);<br />

Arguments: stream stream in which to move the file pointer.<br />

offset value to add to the current position<br />

mode type of seek to perform<br />

Return Value: Returns 0 if successful; otherwise, returns a non-zero value and<br />

set<br />

errno.<br />

Remarks: mode can be one of the following:<br />

SEEK_SET– seeks from the beginning of the file<br />

/ * Chức năng ghi nhận các byte 8. 21 byte * /<br />

/ * Đọc sau đó 18 byte được đọc. Tiếp theo * /<br />

/ * Chức năng fsetpos được thiết lập dựa trên * /<br />

/ * Vị trí fgetpos và theprevious 21 byte * /<br />

/ * Đang đọc lại. * /<br />

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

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

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

/ * Fpos_t, sizeof * /<br />

int main (void)<br />

{<br />

FILE * myfile;<br />

pos fpos_t;<br />

char buf [25];<br />

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

NULL)<br />

printf ("Không thể mở tập tin \ n");<br />

khác<br />

{<br />

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

if (fgetpos (myfile, và pos) = 0)<br />

perror ("fgetpos lỗi");<br />

khác<br />

{<br />

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

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

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

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

}<br />

if (fsetpos (myfile, và pos) = 0)<br />

perror ("fsetpos lỗi");<br />

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

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

fclose (myfile);<br />

}<br />

}<br />

Đầu ra:<br />

Byte đọc: chương trình sẽ mở ra một tập tin<br />

Byte đọc: và đọc byte tại

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

Saved successfully!

Ooh no, something went wrong!