garten
view clock.c @ 18:5937504619f2
rename game.h -> modules.h; added some error handling; and more
author | meillo@marmaro.de |
---|---|
date | Wed, 23 Jul 2008 17:40:55 +0200 |
parents | 5e6c9260913a |
children |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "db.h"
6 int inc_time() {
7 /* get current time */
8 sprintf(query, "select time from game;");
9 stmt = db_query(query);
10 if (sqlite3_step(stmt) == SQLITE_ROW) {
11 gametime = sqlite3_column_int(stmt, 0);
12 } else {
13 db_error("get current time");
14 return 0;
15 }
16 sqlite3_finalize(stmt);
18 /* increment time */
19 sprintf(query,
20 "update game "
21 "set time = '%d';"
22 , ++gametime
23 );
24 if (!db_update(query)) {
25 db_error("time update");
26 return 0;
27 }
28 return 1;
29 }
32 int worldclock(void) {
33 int ret;
35 ret = inc_time();
36 printf("gametime: %d\n", gametime);
38 return ret;
39 }