作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以对于我的部分学校作业,我需要找到当前时间,我将其用作引用:http://www.cplusplus.com/reference/ctime/localtime/我试图复制他们所做的,但我不断收到此错误:
l8stat.c:33: error: called object '15552000' is not a function
这是一行:
time(¤t_time);
我真的不明白为什么我在做与示例相同的事情时会发生这种情况。
这是我的代码:
#include <errno.h>
#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <time.h>
#include <limits.h>
#define SEC_PER_DAY (24 * 60 * 60)
#define time (SEC_PER_DAY*180)
void print_data(char *path ){
setlocale (LC_NUMERIC, "en_US");
struct stat *new=malloc(sizeof(struct stat));
char linkname[PATH_MAX + 1];
int status=lstat(path, new);
if(status==0){
printf("%.6o %9d ",new->st_mode,
new->st_size );
}
else{
fprintf (stderr, "l8stat: %s: %s\n",
path, strerror (errno));
}
time_t current_time;
struct tm *local_time;
time(¤t_time);
local_time=localtime(¤t_time);
char buffer[50];
if(current_time-new->st_mtime<=time ){
strftime(buffer,50,"%b %e %R",new->st_mtime);
puts(buffer);
} else{
strftime(buffer,50,"%b %e %Y",new->st_mtime);
puts(buffer);
}
ssize_t retval = readlink (path, linkname, sizeof linkname);
if(retval >=0){
linkname[retval < PATH_MAX + 1 ? retval : PATH_MAX] = '\0';
printf ("%s -> \"%s\"\n", path, linkname);
}
printf(" %s",path);
}
int main (int argc, char **argv) {
int exit_status=EXIT_SUCCESS;
for(int argi = 1; argi <argc; ++argi){
if(argc!=2) ;
print_data(argv[argi]);
printf("\n");
}
return exit_status;
}
最佳答案
你#define time (SEC_PER_DAY*180)
,然后你调用`time(¤t_time);'
预处理器将展开
time(¤t_time);
根据你的#define:
:
(SEC_PER_DAY*180)(¤t_time);
然后
(24*60*60*180)(¤t_time);
请注意,这发生在实际编译器看到任何东西之前(预处理器在编译器之前运行)。因此,就编译器而言,您正在尝试调用 24*60*60*180
= 15552000
。
关于无法弄清楚这个 "called object is not a function"C 时间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20273402/
我是一名优秀的程序员,十分优秀!