#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
    int n=0;
    FILE *fp;
    if((fp=fopen(argv[1],"r"))==NULL)
    {
        perror("fopen");
        exit(EXIT_FAILURE);
    }
    if(fseek(fp,0,SEEK_END)!=0)
    {
        perror("fseek");
        exit(EXIT_FAILURE);
    }
    if((n=ftell(fp))==-1)
    {
        perror("ftell");
        exit(EXIT_FAILURE);
    }
    printf("the size counted by fseek/ftell of the file is %d \n",n);
    printf("this is ls output:\n");
    execl("/bin/ls","ls","-l",argv[1],(char *)0);
    fclose(fp);
}

在Ubuntu中运行结果

用fseek和ftell获取文件的大小

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2021-07-05
  • 2021-07-09
猜你喜欢
  • 2022-12-23
  • 2022-02-10
  • 2021-07-01
  • 2022-12-23
  • 2021-10-18
  • 2021-08-16
  • 2022-12-23
相关资源
相似解决方案