1、 fseek
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE* pFile = fopen(“C:\\Users\\lucky\\Desktop\\22.txt”, “r”);
char str[20] = { 0 };
fread(str,1,4, pFile);
printf(str);
printf(“\n”);
fseek(pFile, 4L, SEEK_SET);//文件指针指向四个字节
//fseek(pFile, 0L, SEEK_SET);//文件指针指向开头
//fseek(pFile, 4L, SEEK_CUR); //文件指针指向在当前位置向后4字节
//fseek(pFile, -4L, SEEK_END);//文件指针指向结尾向前四个字节
//fseek(pFile, 0L, SEEK_END);//文件指针指向结尾
fread(str,1,4, pFile);
printf(str);
fclose(pFile);
system(“pause”);
return 0;
}
2、ftell
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE* pFile = fopen(“C:\\Users\\lucky\\Desktop\\22.txt”, “r”);
int a = 0;
char str[20] = { 0 };
fread(str,1,4, pFile);
fseek(pFile, 0L,SEEK_END);
a = ftell(pFile);//返回文件指针的当前位置(偏移量)
printf(“%d”,a);
fclose(pFile);
system(“pause”);
return 0;
}