95文件指针

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main() {
FILE*l_fp = fopen("1.txt", "r");
if (!l_fp) {
printf("打开失败\n");
system("pause");
return;
}
fseek(l_fp, 2, SEEK_SET);
int l_last_pos = NULL;
while (!feof(l_fp)) {
char l_temp = fgetc(l_fp);
int l_this_pos = ftell(l_fp);
if (l_last_pos != l_this_pos) {
l_last_pos = l_this_pos;
putchar(l_temp);
}
}
fclose(l_fp);
system("pause");
}

在Windows的txt文件中,一个换行符是由两个字节组成 \r\n  0d 0a

r以及rb模式的区别.  read  和  read byte
w以及wb模式的区别. write和write byte
每一个文件一旦使用fopen建立之后,都有一个文件指针,你可以理解是光标的位置.
默认情况下,文件指针是从前往后依次变化.


fseek
ftell


SEEK_SET  代表文件开头
SEEK_END  代表文件结尾
SEEK_CUR  代表当前位置

posted @ 2018-05-30 22:53  随意就好欧巴  阅读(118)  评论(0编辑  收藏  举报