make timer display show hours and minutes

Este commit está contenido en:
Chris Cromer 2018-11-17 13:34:25 -03:00
padre c4d22ac4da
commit c32dd469d0
Firmado por: cromer
ID de clave GPG: 39CC813FF3C8708A
Se han modificado 1 ficheros con 26 adiciones y 2 borrados

Ver fichero

@ -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);
}