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,


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

Recommended Answers

All 2 Replies

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

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


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.