0

Hi everyone,

I'm trying to get the current time with this function and it's working fine, but, I'm getting the following warning when I compile with gcc 4.4.3 on Linux:

warning: incompatible implicit declaration of built-in function ‘strftime’

I've tried using literals for maxsize and format, but that didn't help.
Can't figure it out.

Thanks for your time,

Tom

// Function returns formatted current time
void get_current_time(char *ptr) {
  struct tm *local;
  time_t t;
  size_t maxsize = 30;
  char *format = "%2e-%2m-%Y %H:%M:%S";

  t = time(NULL);
  local = (void *) localtime(&t);

  strftime(ptr, maxsize, format, local);
}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by tomkaczocha
0

If you check the manpages for strftime, you'll find a complete and working program at the bottom of the listing..

Edited by gerard4143: n/a

0

My bad! :icon_cheesygrin:

I originally wrote that function in main source file then moved it to another source file.

In main I included time.h, but not in the new source file.

Including time.h solved the warning.

Thanks guys

Tom

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.