色www,五月婷婷深爱五月,午夜国产一级片,色噜噜综合,国产大胸无码视频,清纯美女被操黄网站在线观看,波多野结衣av高清一区二区三区

C語(yǔ)言用fstat函數(shù)獲取文件的大小

時(shí)間:2025-10-01 21:26:41 C語(yǔ)言 我要投稿

C語(yǔ)言用fstat函數(shù)獲取文件的大小

  一次偶然在Android的源代碼中看到獲取文件大小的函數(shù),在以下范例中。用fstat這個(gè)函數(shù)可以避免這些問(wèn)題。

  函數(shù)原型:int fstat(int fildes, struct stat *buf);

  參數(shù)說(shuō)明:

  fstat()用來(lái)將參數(shù)fildes所指的文件狀態(tài),復(fù)制到參數(shù)buf所指的結(jié)構(gòu)中(struct stat)。

  寫個(gè)范例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys stat.h="">
#include <unistd.h>
/pic/code>
int get_file_size(int f)
{
    struct stat st;
    fstat(f, &st);
    return st.st_size;
}
 
int main(void)
{
    int fd = open("test.py",O_RDWR);
    int size ;
    if(fd < 0)
    {
        printf("open fair! ");
        return -1 ;
    }
    size = get_file_size(fd) ;
    printf("size:%d字節(jié)--->%.2fK ",size,(float)size/1024);
     
    return 0 ;
}</unistd.h></sys></fcntl.h></stdlib.h></stdio.h>


【C語(yǔ)言用fstat函數(shù)獲取文件的大小】相關(guān)文章:

有關(guān)C語(yǔ)言中獲取文件狀態(tài)的相關(guān)函數(shù)小結(jié)09-21

C語(yǔ)言文件操作函數(shù)11-09

C語(yǔ)言文件操作函數(shù)freopen詳解01-18

C語(yǔ)言最實(shí)用的文件操作函數(shù)大全06-27

C語(yǔ)言超詳細(xì)文件操作函數(shù)大全11-22

C語(yǔ)言文件03-02

C語(yǔ)言文件操作函數(shù)總結(jié)分析(超詳細(xì))02-26

C語(yǔ)言文件操作中fgets與fputs函數(shù)講解02-26

詳解C語(yǔ)言文件操作中fgets與fputs函數(shù)12-31

  • 相關(guān)推薦