garten
annotate clock.c @ 13:f1d43b52ed36
and here now is the main program
author | meillo@marmaro.de |
---|---|
date | Wed, 23 Jul 2008 15:20:35 +0200 |
parents | 176ee28e7464 |
children | 5e6c9260913a |
rev | line source |
---|---|
meillo@0 | 1 #include <stdio.h> |
meillo@0 | 2 #include <stdlib.h> |
meillo@0 | 3 |
meillo@0 | 4 #include "db.h" |
meillo@2 | 5 #include "game.h" |
meillo@0 | 6 |
meillo@0 | 7 |
meillo@0 | 8 |
meillo@12 | 9 |
meillo@2 | 10 void inc_time() { |
meillo@0 | 11 /* get current time */ |
meillo@11 | 12 sprintf(query, "select time from game;"); |
meillo@0 | 13 db_query(query); |
meillo@11 | 14 if (sqlite3_step(stmt) == SQLITE_ROW) { |
meillo@11 | 15 gametime = sqlite3_column_int(stmt, 0); |
meillo@11 | 16 } else { |
meillo@11 | 17 fprintf(stderr, "error: %s\n", sqlite3_errmsg(db)); |
meillo@0 | 18 } |
meillo@11 | 19 sqlite3_finalize(stmt); |
meillo@0 | 20 |
meillo@0 | 21 /* increment time */ |
meillo@11 | 22 sprintf(query, " update game set time = '%d';", ++gametime); |
meillo@12 | 23 if (!db_update(query)) { |
meillo@11 | 24 printf("error: time update failed: %s\n", sqlite3_errmsg(db)); |
meillo@0 | 25 } |
meillo@11 | 26 sqlite3_finalize(stmt); |
meillo@0 | 27 } |
meillo@0 | 28 |
meillo@0 | 29 |
meillo@12 | 30 void worldclock(void) { |
meillo@2 | 31 inc_time(); |
meillo@12 | 32 printf("gametime: %d\n", gametime); |
meillo@0 | 33 } |