ftell 获取文件位置,fseek 把文件指针移动到指定位置

来源:互联网 发布:手机钢琴谱制作软件 编辑:程序博客网 时间:2024/05/21 17:10
#include <stdio.h>#include <stdlib.h>#include <string.h>//ftell 获取文件位置//fseek 把文件指针移动到指定位置int main(int argc,char *argv[]){      FILE *fp;    if(argc !=2)    {        printf("usage %s <filename>\n",argv[0]);        exit(1);    }    fp = fopen(argv[1],"r");    if(fp == NULL)    {        perror("fopen");        exit(1);    }    //获取文件位置    printf("%ld\n",ftell(fp));//long ftell(FILE *stream);    printf("-----%c\n",fgetc(fp));    //把文件指针移动到指定位置    fseek(fp,3,SEEK_SET);    printf("%ld\n",ftell(fp));//long ftell(FILE *stream);    printf("-----%c\n",fgetc(fp));    return 0;}/******编译过程******************/./a.out 19_ftell.c 0-----#3-----c/********************************/
阅读全文
0 0