超碰免费人人操|国产视频二区久久艹人人操|欧美激情第一页在线|久热最新无码中文视频|91精品国际成人|亚洲成人精品在线视频青青草|久草免费高清完整在线观看|你懂的AV在线日本黄网页|国产黄色AV日韩女同网|欧美成人色区导航片av

C語言用fstat函數獲取文件的大小

時間:2025-10-01 21:26:41 C語言 我要投稿

C語言用fstat函數獲取文件的大小

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

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

  參數說明:

  fstat()用來將參數fildes所指的文件狀態(tài),復制到參數buf所指的結構中(struct stat)。

  寫個范例

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語言用fstat函數獲取文件的大小】相關文章:

有關C語言中獲取文件狀態(tài)的相關函數小結09-21

C語言文件操作函數11-09

C語言文件操作函數freopen詳解01-18

C語言最實用的文件操作函數大全06-27

C語言超詳細文件操作函數大全11-22

C語言文件03-02

C語言文件操作函數總結分析(超詳細)02-26

C語言文件操作中fgets與fputs函數講解02-26

詳解C語言文件操作中fgets與fputs函數12-31

  • 相關推薦