From 0246c1ebe8946ef6b681e411b6b6dc678ba5838e Mon Sep 17 00:00:00 2001 From: Abel `00z' Camarillo Date: Sat, 24 May 2008 21:53:32 -0500 Subject: [PATCH] Fixed parsed of input by `,' (commas), now working get_win(). --- final.c | 156 ++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 87 insertions(+), 69 deletions(-) diff --git a/final.c b/final.c index d4d5404..86ff69f 100644 --- a/final.c +++ b/final.c @@ -1,6 +1,10 @@ #include #include +#include +/* + * Structure declaration + */ typedef struct _jugador jugador; struct _jugador @@ -9,25 +13,6 @@ _jugador int anotaciones; }; -typedef struct _deporte deporte; -struct -_deporte -{ - char nombre[128]; - int victorias; - int derrotas; - int anotaciones_favor; - int anotaciones_contra; - jugador estrella; - - /* - * 0 = futbol - * 1 = basket - */ - int num_deporte; - void *tipo_deporte; -}; - typedef struct _futbol futbol; struct _futbol @@ -47,42 +32,77 @@ _basket int triples; }; -int -get_futbol_equipo(deporte *equipo) +typedef struct _deporte deporte; +struct +_deporte { - printf("[Nombre equipo],[victorias],[derrotas],[goles a favor]" - ",[goles en contra] : "); - scanf("%s,%d,%d,%d,%d" - , equipo->nombre - , &equipo->victorias - , &equipo->derrotas - , &equipo->anotaciones_favor - , &equipo->anotaciones_contra - ); - printf("[Nombre jugador estrella] : "); - scanf("%s" - , equipo->estrella.nombre - ); + char *nombre; + int victorias; + int derrotas; + int anotaciones_favor; + int anotaciones_contra; + jugador estrella; - return 1; -} + /* + * 0 = futbol + * 1 = basket + */ + int num_deporte; + void *tipo_deporte; +}; int -get_basket_equipo(deporte *equipo) +get_equipo(deporte *equipo) { - printf("[Nombre equipo],[victorias],[derrotas],[anotaciones a favor]" - ",[anotaciones en contra] : "); - scanf("%s,%d,%d,%d,%d" - , equipo->nombre - , &equipo->victorias - , &equipo->derrotas - , &equipo->anotaciones_favor - , &equipo->anotaciones_contra - ); - printf("[Nombre jugador estrella] : "); - scanf("%s" - , equipo->estrella.nombre - ); + char tmp[1024]; + +/* + * Prints user message + */ + switch ( equipo->num_deporte) + { + + case 0: + printf("[Nombre equipo],[victorias],[derrotas],[goles a favor]" + ",[goles en contra] : "); + break; + + case 1: + printf("[Nombre equipo],[victorias],[derrotas],[anotaciones a favor]" + ",[anotaciones en contra] : "); + break; + + } + +/* + * Gets data + */ + scanf("%s", tmp); + equipo->nombre = strtok(tmp, ","); + sscanf(strtok(NULL, ","), "%d", &equipo->victorias); + sscanf(strtok(NULL, ","), "%d", &equipo->derrotas); + sscanf(strtok(NULL, ","), "%d", &equipo->anotaciones_favor); + sscanf(strtok(NULL, ","), "%d", &equipo->anotaciones_contra); + + +/* + * Gets specific data + */ + switch ( equipo->num_deporte) + { + + case 0: + break; + + case 1: + break; + + } + + printf("[Nombre jugador estrella] : "); + scanf("%s" + , equipo->estrella.nombre + ); return 1; } @@ -91,32 +111,26 @@ int get(deporte **equipos) { while (*equipos) - { - switch ((*equipos)->num_deporte) - { - case 0: - get_futbol_equipo(*equipos); - break; - case 1: - get_basket_equipo(*equipos); - break; - } - equipos++; - } + get_equipo(*equipos),equipos++; return 1; } deporte -get_basket_win(deporte **equipos) +get_win(deporte **equipos) { - deporte winner; - winner.victorias=0; - + deporte winner = **equipos; + while ( *equipos ) - if( (*equipos)->victorias > winner.victorias) - winner=**equipos,equipos++; + { + if( (*equipos)->victorias > winner.victorias) + winner=**equipos; + equipos++; + } + + printf("El ganador de futbol es : %s con %d victorias.\n", winner.nombre + , winner.victorias); return winner; } @@ -157,6 +171,10 @@ main() get(equipos_basket); - get_basket_win(equipos_basket); + deporte winner = get_win(equipos_futbol); + + printf("El ganador de futbol es : %s con %d victorias.\n", winner.nombre + , winner.victorias); + return 1; } -- 2.11.4.GIT