Stephen Wilde
Welcome to my blog here you can find things I have made or I am working on. I program in C/C++, Python, JS, Lua and more.

A simple clock in C

So My goal was to make a simple clock in C++ but I had also been advised to use C so I have made two clocks that do the exact same thing. This is the C version and the next post is the C++ version.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>

int main(int argc, char** argv) {

    time_t now = time(0);
    tm *ltm = localtime(&now);
    printf("Day: %d\nMonth: %d\nYear: %d\n", ltm->tm_mday, ltm->tm_mon, ltm->tm_year);
    printf("Time: %02d:%02d:%02d\n", ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
    printf("The time is correct as long as your system is correct\n");


    goto A;

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *