C - Wrong pointer / integer combination in strftime ()

I get a compiler error: (83) error: wrong pointer / integer combination: arg # 1.

Here is the code that does this:

char boot_time[BUFSIZ];

... line 83:

strftime(boot_time, sizeof(boot_time), "%b %e %H:%M", localtime(table[0].time)); 

where table is a structure and time is a member of time_t.

I read that "incorrect pointer / integer combo" means that the function is undefined (since functions return ints in C when they are not found), and the normal solution should include some libraries. strftime () and localtime () both in time .h and sizeof () in string.h, both of which I included (along with stdio.h), I am completely stopped here.

+3
source share
4 answers
struct tm * localtime ( const time_t * timer );

Proper use :

time_t rawtime;
localtime(&rawtime);

In your case: localtime(&(table[0].time))

+4

localtime time_t*, &table[0].time (, ).

+1

localtime. time_t, . ,

localtime(&(table[0].time))

struct tm * localtime ( const time_t * timer );

API

+1

, , time_t * localtime.

, , . , , , - , , , :

char boot_time[BUFSIZ];
// Temporary, putting the sizeof() call inline is normally better.
size_t boot_time_size = sizeof(boot_time); 
time_t temp_time = table[0].time;
// Use a more descriptive name here.
struct tm *mytime = localtime(temp_time); 

strftime(boot_time, boot_time_size, "%b %e %H:%M", mytime);

That way, the compiler can tell you which call is the one that really gives you problems. Once you figure this out, you can condense it back as you see fit - I would probably leave the localtime () call in my line anyway, but that's just me.

0
source

Source: https://habr.com/ru/post/1709571/


All Articles