fork download
  1. #include <stdbool.h>
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <time.h>
  8.  
  9. #define TIME_PRINTF(format, ...) do { \
  10.   time_t t = time(NULL); \
  11.   const char *prefix = "%s -> "; \
  12.   char time_format_vla[strlen(prefix) + strlen(format) + 1]; \
  13.   strcpy(time_format_vla, prefix); \
  14.   strcat(time_format_vla, format); \
  15.   printf(time_format_vla, ctime(&t), __VA_ARGS__); \
  16. } while (false)
  17.  
  18. int main(void)
  19. {
  20. srand(time(NULL));
  21. TIME_PRINTF("Hello %s, your number is %d! Please wait...\n\n", "User", rand() % 100);
  22.  
  23. // waste some time
  24. for (size_t n=0; n < SIZE_MAX; ++n);
  25.  
  26. // unfortunately, we need to pass at least two parameters
  27. TIME_PRINTF("%s", "So how's it going?");
  28. }
Success #stdin #stdout 12.66s 2424KB
stdin
Standard input is empty
stdout
Wed May 21 08:50:35 2014
 -> Hello User, your number is 28! Please wait...

Wed May 21 08:50:48 2014
 -> So how's it going?