gpt4 book ai didi

c - 打印文件/目录的信息(inode)

转载 作者:太空宇宙 更新时间:2023-11-04 02:50:33 26 4
gpt4 key购买 nike

我想打印一个目录的一些信息。我的代码是:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
#include <string.h>

int main (int argc, char *argv[])
{
struct stat fileStat;
int fd=0;
if ( ( fd = open (argv[1] , O_RDONLY) ) == -1){
perror ( "open " );
exit (1) ;
}

if(fstat(fd, &fileStat)<0) return 1;

printf("Information for %s\n",argv[1]);
printf("---------------------------\n");
--->printf("File Size: \t\t%d bytes\n",fileStat.st_size);
printf("Number of Links: \t%d\n",fileStat.st_nlink);
--->printf("File inode: \t\t%d\n",fileStat.st_ino);

return 0;
}

我收到一些警告:

inode_test.c:24:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__off_t’ [-Wformat]

inode_test.c:26:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__ino_t’ [-Wformat]

箭头表示每个警告所在的行。你能帮我吗?提前致谢!

最佳答案

我找到了答案。这些格式是 long unsigned int。所以它是 %lu。无论如何感谢@haccks 的帮助!

关于c - 打印文件/目录的信息(inode),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22575727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com