Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: mathias_vg en 2 Julio 2013, 14:21 pm



Título: Ayuda!!! Struct para un menu!
Publicado por: mathias_vg en 2 Julio 2013, 14:21 pm
Buenas, solo pretendo que me ayuden con el punto cuatro del menu ya que no me almacena los menu sino que solo me imprime los ultimos, es decir me borra los anteriores. Recurro a ustedes ya que mi profesor solamente dio 5 clases en todo el semestre y nos mato (al menos a mi) con este obligatorio. mi proposito es aprender a  superar esta dificultad con la que estoy trancado. les dejo el codigo un poco mas resumido.

Muchas gracias.


Código
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #define DIM 16 /*Constante utilizada para definir la maxima dimension del tablero*/
  4. //#define tam_string 40 /*Constante para la cantidad de digitos de los Nombres*/
  5. //#define ced_string 8
  6.  
  7. struct partidas1{
  8.        char nom_jug[40];
  9. char ced_jug[8];
  10.    }partidas1[500];
  11. struct partidas2{
  12. char nom_jug[40];
  13. char ced_jug[8];
  14.    }partidas2[500];
  15.    int partida, aux2;
  16.    struct partidas
  17. {
  18.  char nom_jug[40];
  19.  char ced_jug[8];
  20. };
  21.  
  22. struct partidas partidas[10];
  23.  
  24. char nom_jug[40];
  25. char ced_jug[8];
  26.  
  27.  
  28. /*PROCEDIMIENTOS Y FUNCIONES*/
  29.  
  30. void inicializar_tablero(char tablero[][DIM],int);
  31. int juegan_O_(char tabla[][DIM],int,int);
  32. int juegan_X_(char tablero[][DIM],int,int);
  33. int cuatro_en_linea(char tablero[][DIM],int);
  34. int limpiar(char nom_jug[]);
  35.  
  36.  
  37. int inicia1 = 0;
  38. int inicia2 = 0, jugar=1;
  39. int main()
  40. {
  41.    char tablero[DIM][DIM];
  42.    int x,opcion,victoria=1,nombre1,nombre2,contador=1,correcta=1,aux=1,sumador = 0;
  43.    do
  44. {
  45. system("cls");
  46.    printf("\n\n\n     JUEGO CUATRO EN LINEA\n\n\n\n\n");
  47.    printf("  1) Ingresar datos del primer jugador\n\n");
  48.    printf("  2) Ingresar datos del segundo jugador\n\n");
  49.    printf("  3) Jugar\n\n");
  50.    printf("  4) Listar todos los juegos realizados\n\n");
  51.    printf("  5) Salir\n\n\n");
  52.    if (contador%2==0)
  53.     {
  54.     printf("  Error: Antes de jugar debe ingresar los datos de los dos jugadores. \n\n\n");
  55.     printf("  REINGRESE SU OPCION: ");
  56. contador--;
  57.     }
  58.     if (correcta%2==0)
  59.     {
  60.     printf("  Opcion incorrecta \n\n\n");
  61.     printf("  REINGRESE SU OPCION: ");
  62.     correcta--;
  63.     }
  64.     if (aux%2==0)
  65.     {
  66.     printf("  No se han realizado juegos. \n\n\n");
  67.     aux--;
  68.     }
  69.  
  70.    scanf("%d",&opcion);
  71.    system("cls");
  72.    switch (opcion)
  73.    {
  74.    case 1:  /*OPCION 1 DEL MENU.*/
  75.    {
  76.     limpiar(nom_jug);
  77.     limpiar(ced_jug);
  78.     while(getchar() != '\n');
  79.     printf("\n Ingrese su Nombre: ");
  80.     do
  81.     {
  82.     scanf("%39[^\n]",partidas1[inicia1].nom_jug);
  83.     if (partidas1[inicia1].nom_jug[0]=='\0')
  84.     {
  85.     printf(" ERROR\n");
  86.     printf(" Ingrese nuevamente Nombre: ");
  87.     }
  88. else
  89. {
  90.  
  91. for (nombre1=0;nombre1<40;nombre1++)
  92.     {
  93.     nom_jug[nombre1];
  94.     }
  95. }while(getchar() != '\n');
  96. system("cls");
  97.        }while(partidas1[inicia1].nom_jug[0]=='\0');
  98.     printf("\n Ingrese su cedula: ");
  99.     do
  100.     {
  101.     scanf("%8[^\n]",partidas1[inicia1].ced_jug);    
  102.     if (partidas1[inicia1].ced_jug[0]=='\0')
  103.     {
  104.     printf(" ERROR\n");
  105.     printf(" Ingrese nuevamente su cedula: ");
  106.     }
  107. else
  108. {
  109.  
  110. for (nombre1=0;nombre1<8;nombre1++)
  111.     {
  112.     ced_jug[nombre1];
  113.     }
  114.        system("cls");
  115.     printf("\n");
  116. }while(getchar() != '\n');
  117.        }while(partidas1[inicia1].ced_jug[0]=='\0');
  118.        printf("\n    DATOS INGRESADOS\n");
  119.        printf("\n\n   Nombre ingresado: %s",partidas1[inicia1].nom_jug);
  120.     printf("\n\n   Cedula ingresada: %s",partidas1[inicia1].ced_jug);
  121.     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n presione ENTER para volver al menu");
  122.     partidas1[inicia1+1]=partidas1[inicia1];
  123.     jugar++;
  124.     break;
  125.     }
  126.    case 2:  /*OPCION 2 DEL MENU*/
  127.    {
  128. limpiar(nom_jug);
  129.     limpiar(ced_jug);
  130.     while(getchar() != '\n');
  131.     printf("\n Ingrese su Nombre: ");
  132.     do
  133.     {
  134.     scanf("%39[^\n]",partidas2[inicia2].nom_jug);
  135.     if (partidas2[inicia2].nom_jug[0]=='\0')
  136.     {
  137.     printf(" ERROR\n");
  138.     printf(" Ingrese nuevamente Nombre: ");
  139.     }
  140. else
  141. {                        
  142.  
  143. for (nombre2=0;nombre2<40;nombre2++)
  144.     {
  145.     nom_jug[nombre2];
  146.     }
  147. }while(getchar() != '\n');
  148. system("cls");
  149.        }while(partidas2[inicia2].nom_jug[0]=='\0');
  150.     printf("\n Ingrese su cedula: ");
  151.     do
  152.     {
  153.     scanf("%8[^\n]",partidas2[inicia2].ced_jug);  
  154. do
  155.  
  156.     if (partidas2[inicia2].ced_jug[0]=='\0')
  157.     {
  158.     printf(" ERROR\n");
  159.     printf(" Ingrese nuevamente su cedula: ");
  160.     }
  161. else
  162. {
  163.  
  164. for (nombre2=0;nombre2<8;nombre2++)
  165.     {
  166.     ced_jug[nombre2];
  167.     }
  168.     system("cls");
  169.     printf("\n");
  170. }while(getchar() != '\n');
  171.        }while(partidas2[inicia2].ced_jug[0]=='\0');
  172.  
  173.        printf("\n    DATOS INGRESADOS\n");
  174.        printf("\n\n   Nombre ingresado: %s",partidas2[inicia2].nom_jug);
  175.     printf("\n\n   Cedula ingresada: %s",partidas2[inicia2].ced_jug);
  176.     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n presione ENTER para volver al menu");
  177.     partidas2[inicia2+1]=partidas2[inicia2];
  178.     jugar++;
  179.     break;
  180.    }
  181.    case 3: /*OPCION 3 DEL MENU*/
  182.    {
  183.     if (jugar<3)
  184.     {
  185.     contador++;
  186.  
  187.     }
  188.     else  
  189.     {
  190.        cuatro_en_linea(tablero,opcion);
  191.  
  192.  
  193.        sumador++;
  194.        }
  195.        break;
  196.    }
  197.    case 4: /*OPCION 4 DEL MENU*/
  198.    {
  199.     if (sumador<1)
  200.     {
  201.     aux++;
  202.     }
  203.     else
  204.  
  205.     {
  206.             partida=1;
  207.             aux2=0;  
  208.             for(partida;partida<sumador+1;partida++){
  209.             printf("Partida %d\n",partida);
  210.             printf("\n");
  211.             printf("Jugador 1: %s\n",partidas1[aux2].nom_jug);
  212.             printf("Cedula:    %s\n",partidas1[aux2].ced_jug);
  213.             printf("Jugador 2: %s\n",partidas2[aux2].nom_jug);
  214.             printf("Cedula:    %s\n",partidas2[aux2].ced_jug);
  215.             aux2++;
  216.             printf("\n");
  217. }
  218.     }
  219.     system("PAUSE");
  220.     break;
  221.    }
  222.    case 5: /*OPCION 5 DEL MENU*/
  223.    {
  224.     return printf("\n\n  SALIENDO\n\n");
  225.     break;
  226.    default:
  227.     correcta++;
  228.     break;
  229.    }
  230.    }while (getchar()!='\n');
  231.    }while (victoria==1);
  232. }


Título: Re: Ayuda!!! Struct para un menu!
Publicado por: eferion en 2 Julio 2013, 14:42 pm
este hilo está duplicado


Título: Re: Ayuda!!! Struct para un menu!
Publicado por: mathias_vg en 2 Julio 2013, 14:47 pm
Como que esta duplicado?


Título: Re: Ayuda!!! Struct para un menu!
Publicado por: z3nth10n en 2 Julio 2013, 15:01 pm
Que lo has posteado dos veces ;-)