Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/12/2011, 08:26
Bladsmickey
 
Fecha de Ingreso: enero-2011
Mensajes: 33
Antigüedad: 13 años, 3 meses
Puntos: 0
Inscripcion Matrices dinamicas

Saludos, Tengo el siguiente Codigo, el problema es que no funciona!... No se si sera la forma en la cual inicializo las matrices o las aumento, espero me ayuden, Saludos!


Código C:
Ver original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio2.h>
  4. #define p printf
  5. #define s scanf
  6.  
  7. int i,cont=0,op,j=0;
  8. char opc='N';
  9.  
  10.  
  11. struct primaria{
  12. char** nomalu;
  13. char** nompa;
  14. char** cedula;
  15. char** telefono;
  16. char* sexo;
  17. }pri;


Código C:
Ver original
  1. void inscripcion(){
  2. do{
  3. clrscr();
  4. gotoxy(20,1);p("Inscripciones del Colegio Santa maria");
  5. gotoxy(20,2);p("Donde la grandeza se siente\n\n");
  6. fflush(stdin);
  7. p("Introduzca nombre del alumno:\n");
  8. gets(pri.nomalu[cont]);
  9. fflush(stdin);
  10. p("Introduzca nombre del Representante:\n");
  11. gets(pri.nompa[cont]);
  12. fflush(stdin);
  13. p("Introduzca Cedula:\n");
  14. gets(pri.cedula[cont]);
  15. fflush(stdin);
  16. p("Introduzca Telefono:\n");
  17. gets(pri.telefono[cont]);
  18. fflush(stdin);
  19. p("Sexo del representado[M/F]\n");
  20. pri.sexo[cont]=toupper(getchar());
  21. fflush(stdin);
  22. aumentar();
  23. p("Realizar Otra Inscripcion?[S/N]\n");
  24. opc=toupper(getch());
  25. }while(opc=='S');
  26. cont++;
  27. main();
  28. }

Código C:
Ver original
  1. void ver(){
  2. clrscr();
  3. for(i=0;i<cont;i++){
  4. p("Nombre: %s\nNombre Del representante: %s\nCedula: %s\nTelefono: %s\nSexo: %c\n\n", pri.nomalu[i],pri.nompa[i],pri.cedula[i],pri.telefono[i],pri.sexo[i]);
  5. }
  6. }

Código C:
Ver original
  1. void inicializar(){
  2. for(i=0;i<2;i++){
  3. pri.nomalu=(char*)malloc(2*sizeof(char));
  4. pri.nomalu[i]=(char*)malloc(20*sizeof(char));
  5. pri.nompa=(char*)malloc(2*sizeof(char));
  6. pri.nompa[i] = (char *) malloc(20*sizeof(char));
  7. pri.cedula=(char*)malloc(2*sizeof(char));
  8. pri.cedula[i] = (char *) malloc(2*sizeof(char));
  9. pri.telefono=(char*)malloc(20*sizeof(char));
  10. pri.telefono[i] = (char *) malloc(20*sizeof(char));
  11. pri.sexo=(char*)malloc(2*sizeof(char));
  12. }}
Código C:
Ver original
  1. aumentar(){
  2. j++;
  3. pri.nomalu=(char*)realloc(pri.nomalu,1*sizeof(char));
  4. pri.nomalu[j]=(char*)malloc(20*sizeof(char));
  5. pri.nompa=(char*)realloc(pri.nompa,1*sizeof(char));
  6. pri.nompa[j] = (char *) malloc(20*sizeof(char));
  7. pri.cedula=(char*)realloc(pri.cedula,1*sizeof(char));
  8. pri.cedula[j] = (char *) malloc(20*sizeof(char));
  9. pri.telefono=(char*)realloc(pri.telefono,1*sizeof(char));
  10. pri.telefono[j] = (char *) malloc(20*sizeof(char));
  11. pri.sexo=(char*)realloc(pri.sexo,1*sizeof(char));
  12. }


Código C:
Ver original
  1. main(){
  2. clrscr();
  3. inicializar();
  4.     do{
  5. gotoxy(20,1);p("Bienvenido Al colegio Santa maria");
  6. gotoxy(20,2);p("EsperemoInscripcion Matrices dinamicass tenga un grandiso dia");
  7. gotoxy(20,6);p("1. Realizar Inscripcion");
  8. gotoxy(20,7);p("2. Ver Alumnos Inscritos");
  9. gotoxy(20,8);p("3. Salir");
  10. gotoxy(20,9);p("Opcion:   ");
  11.  
  12. s("%d", &op);
  13. switch(op){
  14.     case 1:{
  15.     inscripcion();
  16.     }break;
  17.     case 2:{
  18.     ver();
  19.     }break;
  20. }
  21.  
  22.  
  23. }while(op=!3);
  24. }