File: printf_format.c

package info (click to toggle)
libdate-manip-perl 6.98-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,928 kB
  • sloc: perl: 222,846; sh: 54; ansic: 26; makefile: 8
file content (32 lines) | stat: -rw-r--r-- 591 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, char *argv[]) {
   char   *format;
   char   outstr[200];
   time_t t;
   struct tm *tmp;
 
   format = argv[1];
   if (argc > 2) {
      t   = (time_t) atoll(argv[2]);
   } else {
      t   = time(NULL);
   }

   tmp = localtime(&t);
   if (tmp == NULL) {
       perror("localtime");
       exit(EXIT_FAILURE);
   }

   if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) {
       fprintf(stderr, "strftime returned 0");
       exit(EXIT_FAILURE);
   }

   printf("%s\n", outstr);
   exit(EXIT_SUCCESS);
}