- 打开文件
#include <stdio.h> FILE *fp; fp = fopen("file.txt", "r"); if( NULL==fp )
- 获取文件大小
fseek(fp,0L,SEEK_END); /**< 定位至文件结尾*/ fileLen = ftell(fp); /**<得到文件字节数 */ p = (char *)malloc(fileLen + 1); /**<分配空间大小要 +1 */ /**< NULL==p*/ fseek(fp,0L,SEEK_SET);/**< 定位至文件开始处*/ fread(p,fileLen ,1,fp); p[fileLen ] =0; fseek(fp, -10, SEEK_END); /**< 从文件结尾处回退10个字节*/ fseek(fp, 2L, SEEK_CUR); /**<从文件当前位置前移2个字节*/ fseek(fp, 10L, SEEK_SET); /**<定位至文件中的第10个字节*/