From 8538498d32b83b7517302141030936a673842a66 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Tue, 20 Jun 2017 15:04:17 +0200 Subject: Added editing of current activity, updated menu and renamed all current_activity to new_activity. --- timetracker.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/timetracker.c b/timetracker.c index 0d3d18f..5c805db 100644 --- a/timetracker.c +++ b/timetracker.c @@ -4,9 +4,10 @@ #include #include -void print_current_activity(); +void print_new_activity(); void start_new_activity(); -void stop_current_activity(); +void stop_new_activity(); +void edit_new_activity(); void print_activities(); void save_to_file(); void load_file(); @@ -18,22 +19,22 @@ typedef struct activities char description[100]; } activity; -activity current_activity; +activity new_activity; activity activities_list[100]; int main() { - strcpy(current_activity.description,"N/A"); - current_activity.start_time = time(NULL); + strcpy(new_activity.description,"N/A"); + new_activity.start_time = time(NULL); load_file(); char command; while(command != 'q') { system("clear"); - print_current_activity(); + print_new_activity(); print_activities(); - printf("\n\n[s]tart tracking new activity | sto[p] current activity | sa[v]e to file | [q]uit: "); + printf("\n\n[s]tart/sto[p]/[e]dit new activity | sa[v]e to file | [q]uit: "); fgets(&command, 256, stdin); switch(command) { @@ -42,7 +43,11 @@ int main() break; case 'p': - stop_current_activity(); + stop_new_activity(); + break; + + case 'e': + edit_new_activity(); break; case 'v': @@ -59,19 +64,19 @@ int main() return 0; } -void print_current_activity() +void print_new_activity() { time_t time_now = time(NULL); char buf[80]; - strftime(buf, sizeof(buf), "%H:%M:%S", localtime(¤t_activity.start_time)); + strftime(buf, sizeof(buf), "%H:%M:%S", localtime(&new_activity.start_time)); printf("==================================================" "==================================================\n" "Current activity: %s\nStart time: %s\nDuration: %ld mins.\n" "==================================================" "==================================================\n", - current_activity.description, buf, (time_now - current_activity.start_time)/60); + new_activity.description, buf, (time_now - new_activity.start_time)/60); } void print_activities() @@ -95,29 +100,36 @@ void print_activities() void start_new_activity() { - current_activity.start_time = time(NULL); + new_activity.start_time = time(NULL); printf("\nWhat are you doing: "); - fgets(current_activity.description, 256, stdin); - current_activity.description[strcspn(current_activity.description, "\n")] = 0; + fgets(new_activity.description, 256, stdin); + new_activity.description[strcspn(new_activity.description, "\n")] = 0; } -void stop_current_activity() +void stop_new_activity() { - current_activity.end_time = time(NULL); + new_activity.end_time = time(NULL); for(int i = 0; i < 100; i++) { if(!activities_list[i].start_time) { - activities_list[i] = current_activity; - strcpy(current_activity.description, "N/A"); + activities_list[i] = new_activity; + strcpy(new_activity.description, "N/A"); break; } } } +void edit_new_activity() +{ + printf("\nWhat are you doing: "); + fgets(new_activity.description, 256, stdin); + new_activity.description[strcspn(new_activity.description, "\n")] = 0; +} + void save_to_file() { FILE *fp; -- cgit v1.2.3