想不通这个"所谓的对象不是一个函数" C时间错误 [英] Can't figure out this "called object is not a function" C time error
问题描述
所以,我校任务的一部分,我需要找到当前的时间,我用这个作为参考:的 http://www.cplusplus.com/reference/ctime/localtime/
我试图复制他们做了什么,但我不断收到此错误:
l8stat.c:33:错误:调用的对象'15552000'不是一个函数
这是该行:
时间(安培; CURRENT_TIME);
我真的不明白为什么当我在做同样的事情的例子发生这种情况。
下面是我的code:
的#include<&errno.h中GT;
#包括LT&;&libgen.h GT;
#包括LT&;&string.h中GT;
#包括LT&;&unistd.h中GT;
#包括LT&; SYS / types.h中>
#包括LT&; SYS / stat.h>
#包括LT&;&time.h中GT;
#包括LT&;&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&locale.h文件GT;
#包括LT&;&time.h中GT;
#包括LT&;&limits.h中GT;#定义SEC_PER_DAY(24 * 60 * 60)
#定义时间(SEC_PER_DAY * 180) 无效print_data(字符*路径){
的setlocale(LC_NUMERIC,用en_US);
struct stat中*新的malloc =(sizeof的(struct stat中));
字符链接名称[PATH_MAX + 1];
INT状态= LSTAT(路径,新的);
如果(状态== 0){
%60%9D的printf(,新建 - > ST_MODE,
新建 - > st_size);
}
其他{
fprintf中(标准错误,l8stat:%S:%S \\ n,
路径字符串错误(错误));
} time_t的CURRENT_TIME;
结构TM * LOCAL_TIME;
时间(安培; CURRENT_TIME);
LOCAL_TIME =本地时间(安培; CURRENT_TIME);
字符缓冲区[50];
如果(CURRENT_TIME - 新建 - > st_mtime< =时间){
的strftime(缓冲,50,%B%E%R,新建 - > st_mtime);
看跌(缓冲液);
}其他{
的strftime(缓冲,50,%B%E%Y,新建 - > st_mtime);
看跌(缓冲液);
} ssize_t供RETVAL =的readlink(路径,链接名称,sizeof的链接名称);
如果(RETVAL> = 0){
链接名称[RETVAL< PATH_MAX + 1? RETVAL:PATH_MAX] ='\\ 0';
的printf(%S - > \\%s \\的\\ n,路径链接名称);
} 的printf(%S,路径);
}INT主(INT ARGC,字符** argv的){
INT EXIT_STATUS = EXIT_SUCCESS;
对于(INT阿尔吉= 1;阿尔吉< ARGC ++阿尔吉){
如果(ARGC = 2!);
print_data(的argv [阿尔吉]);
的printf(\\ n);
} 返回EXIT_STATUS;
}
您的#define时间(SEC_PER_DAY * 180)
,那么以后你叫'时间(安培; CURRENT_TIME );
在preprocessor将扩展
时间(安培; CURRENT_TIME);
按你的的#define:
:
(SEC_PER_DAY * 180)(安培; CURRENT_TIME);
然后
(24 * 60 * 60 * 180)(安培; CURRENT_TIME);
请注意,出现这种情况的实际编译器看到任何东西之前(preprocessor编译之前运行)。所以只要编译器而言,你想叫 24 * 60 * 60 * 180
= 15552000
So for part of my school assignment, I need to find the current time, and i used this as a reference:http://www.cplusplus.com/reference/ctime/localtime/ I tried to copy what they did, but I keep getting this error:
l8stat.c:33: error: called object '15552000' is not a function
This is the line:
time(¤t_time);
I really don't understand why this is happening when I'm doing the same thing as the example.
Here's my code:
#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;
}
You #define time (SEC_PER_DAY*180)
, then later you call `time(¤t_time);'
The preprocessor will expand
time(¤t_time);
as per your #define:
:
(SEC_PER_DAY*180)(¤t_time);
and then
(24*60*60*180)(¤t_time);
Note that this happens before the actual compiler sees anything (the preprocessor runs before the compiler). So as far as the compiler is concerned, you're trying to call 24*60*60*180
= 15552000
.
这篇关于想不通这个&QUOT;所谓的对象不是一个函数&QUOT; C时间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!