我收到C语言的警告
我想检查一个日期是否已经过了,但我收到了编者的警告我收到C语言的警告,c,C,我想检查一个日期是否已经过了,但我收到了编者的警告 warning: initialization of 'int' from 'char *' makes integer from pointer without a cast warning: comparison between pointer and integer 正如你可能看到的,我刚开始学习C语言 #include <stdio.h> #include <time.h> int main() {
warning: initialization of 'int' from 'char *' makes integer from pointer without a cast
warning: comparison between pointer and integer
正如你可能看到的,我刚开始学习C语言
#include <stdio.h>
#include <time.h>
int main()
{
time_t rawtime;
struct tm* timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
printf("----------------------------------------\n");
strftime(buffer, 80, "%d%m%H%M", timeinfo); // Get date and time and format it as DDMMHM and store it in buffer
puts(buffer); // Print date stored in buffer
printf("----------------------------------------\n");
int as = "22051222"; // Set an int according to date of the first conditon
if ( as < buffer ) { // if as < than the date saved in buffer
printf("22/05/2020 - 12:22 ------ Florian.M\n\n"); // then print this line
} else {
printf("22/05/2020 - 12:22 ------ Florian.M>>>\n\n"); // else print this line
}
printf("----------------------------------------\n");
getchar();
return 0;
}
哪种方法是最好的
int as = "22051222";
如果需要字符串,请将其转换为char*。如果需要整数,请删除该行中的引号。:
if ( as < buffer )
int as=22051222;不,如果OP花了30多秒重新阅读他的代码,这个问题本来可以避免的。这个问题太快就解决了。投票重新打开。我投票的是一个打字错误,不是关于需要调试details@Cid是的,如果人们出于不同的原因投票,那么它会给出一个错误的信息,即他们都投票给其中一个。我想如果我想让这一切正确,那么我需要正确地开始阅读和学习。谢谢你的回答,朋友
char as[] = "22051222";
if (strcmp(as,buffer) < 0)