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

#define _CRT_SECURE_NO_WARNINGS#include#include //包含两个头文件#include #include #include #include //获取文件状态void test01(){//先创建一个结构体变量struct stat mystat;stat("hello.txt", &mystat);printf("文件的大小%d\n", 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;}

#define _CRT_SECURE_NO_WARNINGS#include#include //包含两个头文件#include #include #include #include //获取文件状态void test01(){//先创建一个结构体变量struct stat mystat;stat("hello.txt", &mystat);printf("文件的大小%d\n", 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;}











