随机读写
ftell(fp) long int
测试文件光标所在位置到起始位置有多少字节
fseek定位光标位置
int fseek(fp,100(位移量),int whence(起始点))
whence
SEEK_CUR 1 光标当前位置
SEEK_END 2 文档末尾
SEEK_SET 0 文档开头
位移量
以起始点为基点向前向后的字节数,正数往文件末尾偏移,负数向文件开头偏移
重定向
FILE *freopen(文件名,打开模式,标准名文件(stdin/stdout/stderr))
以上是今天所学,下面有两道练习题来巩固文件的学习
//1
int main(){
FILE *fpa = fopen("./A.txt","w+");
char a[100] = "qwertyuiopzxc";
fprintf(fpa,"%s",a);
rewind(fpa);
char a_a[100];
fscanf(fpa,"%s",a_a);
printf("%s\n",a_a);
fclose(fpa);