News for hackers. Stuff that matters.

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 )
Re:epoch.c by hknapp on Wednesday September 06, 2023 @09:59PM (#37413809)
What is going on here
Re:epoch.c by qazxcvbnmlp on Wednesday September 06, 2023 @09:59PM (#37413812)
It prints the current epoch time
Re:epoch.c by hknapp on Wednesday September 06, 2023 @10:04PM (#37413845)
I'm wondering what's special about it. Also, what is up with the other comments.
Re:epoch.c by webkike on Wednesday September 06, 2023 @10:02PM (#37413829)
For those of you wondering what this does, it prints out the time in seconds since the Unix epoch.

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

Re:epoch.c by ketanmaheshwari on Wednesday September 06, 2023 @10:05PM (#37413850)
Why / how is it important to post a code block as a post? Anyone know relevance?