tags:

views:

310

answers:

5

I'm getting the compiler error: (83) error: improper pointer/integer combination: arg #1.

Here's the code that is doing it:

char boot_time[BUFSIZ];

... Line 83:

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

where table is a struct and time is a time_t member.

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

+1  A: 

localtime takes a time_t*, so pass &table[0].time (the address, not the value).

Alex Martelli
+1  A: 

The problem appears to be the call into localtime. This function is expecting a time_t pointer and not a value. I believe you need to make your call as follows

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

Signature of localtime

struct tm * localtime ( const time_t * timer );

Reference to the localtime API

JaredPar
+4  A: 
struct tm * localtime ( const time_t * timer );

The correct usage is :

time_t rawtime;
localtime(&rawtime);

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

aJ
A: 

As others have mentioned, the particular problem is that you need to pass a time_t * to localtime.

However, the general problem was that you had an unclear problem on a complicated line that did multiple things. The first thing to have tried when you got the error would be to split the line up into its component parts, to narrow down exactly where the problem is, like so:

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

This way the compiler can tell you which call is the one that's actually giving you problems. Once you've figured it out, you can condense it back down as you see fit - I'd probably still keep the localtime() call on its own line, but that's just me.

C Pirate
A: 

Yep, I just needed to pass the address of the time_t into local time instead of the pointer. Thank you!