Cualquier razón específica por la que Localtime lanza advertencia con Struct TM * & Stat *, en Linux?

StackOverflow https://stackoverflow.com//questions/11676935

Pregunta

Tengo este código simple (parte de un proyecto):

void displayFileProperties(struct stat* file,char*  outputProperties , char * path)
{

    struct tm* time;

        // code 
        // code
        time = localtime(&file->st_mtim);


        // code 

}

donde Eclipse me sigue lanzándome una advertencia:

passing argument 1 of ‘localtime’ from incompatible pointer type [enabled by default]   main.c  /ex4    line 340    C/C++ Problem

¿Alguna idea de cómo solucionar esto?gracias

¿Fue útil?

Solución

st_mtim es un Tiempo de estructura (segundos y nanosegundos).Quieres st_mtime.

Otros consejos

Querrás usar esto en su lugar:

time = localtime(&file->st_mtime);

Nota el 'E' agregado al final.st_mtim es un TimesPec, con 'E' agregó que es un tiempo_t (lo que necesita).

Respuesta completamente cambiada:

Sugerencias:

1) Asegúrese de que #inClude estos encabezados:

#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>

2) Etrice su puntero a "Const"

time = localtime((const time_t *)&file->st_mtime);

3) Publique lo que sucede

=====================================================

Sugerencias adicionales:

1) Lea estos dos enlaces:

Tuve el mismo problema con Eclipse: El campo St_mtime no se pudo resolver (error semántico)

Se solucionó el problema en Eclipse haciendo clic con el botón derecho en el proyecto, elija Índice -> "Refrescar todos los archivos"

#include <malloc.h>
#include <time.h>
#include <stdio.h>

static struct tm* alarmTime(void);

int main(){
    printf("Hour :%i\n", alarmTime()->tm_hour);
    printf("Minute :%i\n", alarmTime()->tm_min);
    return 0;
}

static struct tm* alarmTime(void){
    time_t now = time(NULL);
    struct tm* ptm;
#ifdef HAVE_LOCALTIME_R
    struct tm tmbuf;
    ptm = localtime_r(&now, &tmbuf);
#else
    ptm = localtime(&now);
#endif
    return ptm;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top