From fdc0836f094f99d7437d3db8ca00bd638c161d95 Mon Sep 17 00:00:00 2001 From: Abel `00z' Camarillo Date: Sat, 24 May 2008 22:07:02 -0500 Subject: [PATCH] Some code cleaning. --- final.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/final.c b/final.c index 86ff69f..6d8d9dc 100644 --- a/final.c +++ b/final.c @@ -129,49 +129,46 @@ get_win(deporte **equipos) equipos++; } - printf("El ganador de futbol es : %s con %d victorias.\n", winner.nombre - , winner.victorias); return winner; - +} + +/* + * Allocate memory + */ +deporte ** +alloc_mem(int LIM) +{ + deporte **tmp = malloc(sizeof(void *)*(LIM+1)); + + int i; + for(i=0;inum_deporte = 0 + , tmp[i]->tipo_deporte = malloc(sizeof(futbol)); + tmp[LIM] = NULL; + + return tmp; } int main() { - int i=0; int LIM=0; printf("Numero de equipos futbol : "); scanf("%d", &LIM); - deporte **equipos_futbol = malloc(sizeof(void *)*(LIM+1)); + deporte **equipos_futbol = alloc_mem(LIM); - /* - * Allocate memory - */ - for(i=0;inum_deporte = 0 - , equipos_futbol[i]->tipo_deporte = malloc(sizeof(futbol)); - equipos_futbol[LIM] = NULL; printf("Numero de equipos basket : "); scanf("%d", &LIM); - - /* - * Allocate memory - */ - deporte **equipos_basket = malloc(sizeof(void *)*(LIM+1)); - for(i=0;inum_deporte = 1 - , equipos_basket[i]->tipo_deporte = malloc(sizeof(basket)); - equipos_basket[LIM] = NULL; + deporte **equipos_basket = alloc_mem(LIM); get(equipos_futbol); get(equipos_basket); - deporte winner = get_win(equipos_futbol); + deporte winner = get_win(equipos_futbol); printf("El ganador de futbol es : %s con %d victorias.\n", winner.nombre , winner.victorias); -- 2.11.4.GIT