Cleanup source #23

Merged
cromer merged 3 commits from cleanup into master 2018-11-17 13:36:44 -03:00
1 changed files with 26 additions and 2 deletions
Showing only changes of commit c32dd469d0 - Show all commits

View File

@ -15,7 +15,6 @@
#include <stdio.h>
#include <time.h>
#include "timer.h"
/**
* Cuando empezó el timer
@ -57,7 +56,26 @@ void print_timer() {
fprintf(stderr, "Error: El temporizador no ha terminado todavía!\n");
}
else {
fprintf(stdout, "Tiempo de ejecución: %ld segundos\n", (long int) (stop_time - start_time));
long int seconds = (long int) (stop_time - start_time);
long int minutes = 0;
long int hours = 0;
if (seconds >= 3600) {
hours = seconds / 3600;
seconds = seconds - (hours * 3600);
if (seconds >= 60) {
minutes = seconds / 60;
seconds = seconds - (minutes * 60);
}
fprintf(stdout, "Tiempo de ejecución: %ld horas, %ld minutos y %ld segundos\n", hours, minutes, seconds);
}
else if (seconds >= 60) {
minutes = seconds / 60;
seconds = seconds - (minutes * 60);
fprintf(stdout, "Tiempo de ejecución: %ld minutos y %ld segundos\n", minutes, seconds);
}
else {
fprintf(stdout, "Tiempo de ejecución: %ld segundos\n", seconds);
}
}
}
@ -66,5 +84,11 @@ void print_timer() {
* @return El tiempo que demoró
*/
long int get_timer() {
if (start_time == 0) {
fprintf(stderr, "Error: El temporizador no ha comenzado todavía!\n");
}
else if (stop_time == 0) {
fprintf(stderr, "Error: El temporizador no ha terminado todavía!\n");
}
return (long int) (stop_time - start_time);
}