vi 1.0.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#define BUF 100
void print_time(time_t ct,char* s)
{
char st[BUF];
printf("%s: ",s);
strftime(st,BUF,"%Y %x %X",localtime(&ct));
printf("%s\n",st);
}
int main(int argc,char* argv[])
{
if (argc != 2)
{
printf("you need <pathname>\n");
exit(0);
}
struct stat statbuf;
if (lstat(argv[1],&statbuf) < 0)
{
printf("lstat error\n");
exit(0);
}
char *s = "文件最后访问时间为";
print_time(statbuf.st_atime,s);
s = "文件最后修改时间为";
print_time(statbuf.st_mtime,s);
s = "文件最后状态改变时间为";
print_time(statbuf.st_ctime,s);
}
运行:
本文介绍了一个使用C语言编写的程序,该程序通过命令行接收一个文件路径作为输入参数,并利用lstat函数获取该文件的最后访问时间、最后修改时间和最后状态改变时间。这些时间信息以易读的格式打印出来。
2008

被折叠的 条评论
为什么被折叠?



