/*倒序显示文本内容: linux环境*/ #include<stdio.h> #include<stdlib.h> #define SLEN 81 int main(void) { char *file = "hello.txt"; char ch; FILE *fp; long count, last; if ((fp = fopen(file, "rb")) == NULL) {//只读,fopen 会创建:1. 文件结构体, 2. 缓冲区(这里只建立一个读缓冲区) printf("Error\n"); exit(1); } fseek(fp, 0L, SEEK_END); last = ftell(fp); for (count = 1L; count <= last; count++) { fseek(fp, -count, SEEK_END);//定位到文件末尾向前数count ch = getc(fp); putchar(ch); } putchar('\n'); fclose(fp); return 0; }
标签:fp,count,文本,char,file,Linux,倒序 From: https://www.cnblogs.com/cedar007/p/17372364.html