#include <stdio.h>
#include <stdlib.h>
#define LINE_SIZE = 512
int main(void)
{
FILE *file = NULL;
int fileEnd = 0;
int n = 0;
char buf[512] = {0};
file = fopen("filepath","r");
fseek( file, 0,SEEK_END );
fileEnd = ftell(file);
for(n = 0; n <= fileEnd; n++) {
fseek(file, -n, SEEK_END);
if( getc(file) == '\n') {
n--;
fseek(file, -n, SEEK_END);
fgets(buf, n, file);
printf("%s", buf);
n+=2; //如果+1,会有换行,必须+2
}
}
return 0;
}
从后往前读文件
最新推荐文章于 2022-04-05 13:00:53 发布