gpt4 book ai didi

c - 为什么 ftell 会跳过文件中的某些位置?

转载 作者:太空狗 更新时间:2023-10-29 15:39:59 25 4
gpt4 key购买 nike

<分区>

我有一个名为 myfile.txt 的文本文件,内容如下:

line 1
l

我的代码:

#include<stdio.h>
int main(){
FILE *f = fopen("myfile.txt","r");
if(f==NULL){
FILE *fp=fopen("myfile.txt","w");
fclose(fp);
f = fopen("myfile.txt","r");
}
while(!feof(f)){
printf("\ncharacter number %d ",ftell(f));
putchar(fgetc(f));
}
fclose(f);
return 0;
}

输出是:

character number 0    l
character number 1 i
character number 2 n
character number 3 e
character number 4
character number 5 1
character number 6

character number 8 l
character number 9  

每当遇到\n 时,ftell 都会跳过一个值,例如它已跳过值 7。为什么会这样?请详细解释我,我想知道。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com