epoch.c
int puts(const char *);
unsigned int time(unsigned int *tloc);
char *itoa(int x){
static char buf[21];
char *s=buf+20;
if(x>=0){do{*--s='0'+(x%10);x/=10;}while(x!=0);return s;}
else{do{*--s='0'-(x%10);x/=10;}while(x!=0);*--s='-';};
return s;}
int main(){puts(itoa(time(0)));}
(
5 comments
| on HN
)
It doesn’t do it in a particularly interesting way - the meat of this is implementing the itoa function (integer to array) that converts a number to a string. That implementation is itself not particularly special, just fairly condensed. Everything else is done with standard library functions