获取文件状态

获取文件状态

stat结构体中很多属性在linux系统下才有效,windows系统下无效

代码语言:javascript代码运行次数:0运行复制

#define _CRT_SECURE_NO_WARNINGS#include#include//包含两个头文件#include#include#include#include//获取文件状态void test01(){//先创建一个结构体变量struct stat mystat;stat("hello.txt", &mystat);printf("文件的大小%dn", mystat.st_size);//获取atime----最后一次访问时间//ctime返回值是char* char* p = ctime(&mystat.st_atime);printf("%s", p);//因为返回的字符串中包含了换行//去掉换行//方法1://因为指针指向的可能是一个字符串常量,所以强行修改可能会报错char buf[64] = { 0 };strcpy(buf, p);//遇到结束拷贝//去掉字符串结尾的nbuf[strlen(buf) - 1] = '';printf("%s", buf);}int main(){test01();system("pause");return 0;}
获取文件状态

代码语言:javascript代码运行次数:0运行复制

#define _CRT_SECURE_NO_WARNINGS#include#include//包含两个头文件#include#include#include#include//获取文件状态void test01(){//先创建一个结构体变量struct stat mystat;stat("hello.txt", &mystat);printf("文件的大小%dn", mystat.st_size);//获取atime----最后一次访问时间//ctime返回值是char* char* p = ctime(&mystat.st_atime);printf("%s", p);//因为返回的字符串中包含了换行//去掉换行//方法2://因为指针指向的可能是一个字符串常量,所以强行修改可能会报错char buf[64] = { 0 };//拷贝到n结束strncpy(buf, p, strlen(p)-1);printf("%s", buf);}int main(){test01();system("pause");return 0;}
获取文件状态

代码语言:javascript代码运行次数:0运行复制

#define _CRT_SECURE_NO_WARNINGS#include#include//包含两个头文件#include#include#include#include//获取文件状态void test01(){//先创建一个结构体变量struct stat mystat;stat("hello.txt", &mystat);printf("文件的大小%dn", mystat.st_size);//获取mtime------最后一次修改时间char* p = ctime(&mystat.st_mtime);char buf[64] = { 0 };strcpy(buf, p);printf("%s", buf);}int main(){test01();system("pause");return 0;}
获取文件状态

以上就是获取文件状态的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/96876.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年11月20日 00:56:50
下一篇 2025年11月20日 01:24:20

相关推荐

发表回复

登录后才能评论
关注微信