我正在学习C程序.当尝试运行代码时,我收到错误:[错误] ld返回1退出状态
#include <stdio.h>
#include <time.h>
void main()
{
time_t t;
time(&t);
clrscr();
printf("Today's date and time : %s",ctime(&t));
getch();
}
Run Code Online (Sandbox Code Playgroud)
谁能解释一下我在这里做错了什么?
我试过这段代码:
int main()
{
printf("Today's date and time : %s \n", gettime());
return 0;
}
char ** gettime() {
char * result;
time_t current_time;
current_time = time(NULL);
result = ctime(¤t_time);
return &result;
}
Run Code Online (Sandbox Code Playgroud)
但仍然显示错误为:错误:被叫对象'1'不是current_time = time(NULL)中的函数; 线.代码有什么问题
我想你在寻找这样的东西:
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
time_t current_time;
char* c_time_string;
current_time = time(NULL);
/* Convert to local time format. */
c_time_string = ctime(¤t_time);
printf("Current time is %s", c_time_string);
return 0;
}
Run Code Online (Sandbox Code Playgroud)