1¡¢Îļþ¶¨Î»
Ö¸¶ÁÈ¡»òÉèÖÃÎļþµ±Ç°¶Áдµã£¬ËùÓеÄͨ¹ýÎļþÖ¸Õë¶ÁдµÄº¯Êý£¬¶¼ÊÇ´ÏÃ÷ºÍÎļþµÄµ±Ç°¶Áдµã¶ÁдÊý¾ÝµÄ.
³£Óõĺ¯ÊýÓУº
#include <stdio.h>
int fseek(FILE *stream, long offset, int whence);
//ÉèÖõ±Ç°¶Áдµãµ½Æ«ÒÆ whence£¬³¤¶ÈΪ offset ´¦
fseek ÉèÖõ±Ç°¶Áдµãµ½Æ«ÒÆ whence ³¤¶ÈΪoffset´¦£¬whence¿ÉÒÔÊÇ
SEEK_SET (Îļþ¿ªÍ·
SEEK_CUR(Îļþµ±Ç°Î»ÖÃ
SEEK_END(Îļþĩβ
fseek ʹÓÃʾÀý£º
#include <stdio.h>
int main()
{
char buf[50] = {'h','e','l','l','o'};
FILE *p;
p = fopen("a.txt", "r+b");¡£
fwrite(buf, 1, 5, p);
char buf1[50] = {0};
fseek(p, 0, SEEK_SET);
fread(buf1, 1, 5, p);
printf("buf1:%s\n", buf1);
fclose(p);
return 0;
}
int feof(FILE * stream); //ͨ³£µÄÓ÷¨Îª while(!feof(fp))
º¯Êý¹¦ÄÜ£ºfeof ÅжÏÊÇ·ñµ½´ïÎļþĩβµÄÏÂÒ»¸ö£¨×¢Òâµ½µ½´ïÎļþĩβ֮ºó»¹»á×öÒ»´Î£©
long ftell(FILE *stream); //ÓÃÀ´»ñµÃÎļþÁ÷µ±Ç°µÄ¶ÁдλÖÃ
º¯Êý¹¦ÄÜ£ºftell »ñÈ¡µ±Ç°µÄ¶Áдµã
void rewind(FILE *stream); //°ÑÎļþÁ÷µÄ¶ÁдλÖÃÒÆÖÁ¿ªÍ·£¬fseek(fp,0,SEEK_SET);
º¯Êý¹¦ÄÜ£ºrewind ½«Îļþµ±Ç°¶ÁдµãÒƶ¯µ½ÎļþÍ·