gpt4 book ai didi

无法弄清楚这个 "called object is not a function"C 时间错误

转载 作者:行者123 更新时间:2023-12-02 04:43:38 25 4
gpt4 key购买 nike

所以对于我的部分学校作业,我需要找到当前时间,我将其用作引用:http://www.cplusplus.com/reference/ctime/localtime/我试图复制他们所做的,但我不断收到此错误:

l8stat.c:33: error: called object '15552000' is not a function

这是一行:

time(&current_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(&current_time);
local_time=localtime(&current_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(&current_time);'

预处理器将展开

time(&current_time);

根据你的#define::

(SEC_PER_DAY*180)(&current_time);

然后

(24*60*60*180)(&current_time);

请注意,这发生在实际编译器看到任何东西之前(预处理器在编译器之前运行)。因此,就编译器而言,您正在尝试调用 24*60*60*180 = 15552000

关于无法弄清楚这个 "called object is not a function"C 时间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20273402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com