我在C语言中收到警告

问题描述 投票:-4回答:2

我想检查日期是否已经过去,但是我收到来自编译器的警告

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;
}

哪个是最好的方法

c
2个回答
2
投票

在此行:

if ( as < buffer ) 

1
投票
int as = "22051222";  
© www.soinside.com 2019 - 2024. All rights reserved.