May 2019
Intermediate to advanced
478 pages
11h 21m
English
Before we begin the networked program, it is useful to solve our problem with a simple console program first. In general, it is a good idea to work out your program's functionality locally before adding in networked features.
The local, console version of our time-telling program is as follows:
/*time_console.c*/#include <stdio.h>#include <time.h>int main(){ time_t timer; time(&timer); printf ("Local time is: %s", ctime(&timer)); return 0;}
You can compile and run it like this:
$ gcc time_console.c -o time_console$ ./time_consoleLocal time is: Fri Oct 19 08:42:05 2018
The program works by getting the time with the built-in C time() function. It then converts it into a string with the ctime() function.
Read now
Unlock full access