- 论坛徽章:
- 0
|
从struct stat中获取file的 time of last access,并用char *ctime(time_t *t)转换成可读形式
以下是我写的一段程序,程序编译正常通过,当运行时返回:Segmentation fault
请问是怎么回事,谢谢了。
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
int main(int args,char *argv[]){
struct stat * statbuf;
if(args < 2){
printf("please input a file\n");
exit(1);
}
if(stat(argv[1],statbuf) == 0){
time_t t = statbuf->st_atime;
printf("%s\n",ctime(&t));
}
else{
perror(argv[1]);
exit(1);
}
return 0;
}
|
|
|