• Viernes 26 de Abril de 2024, 15:38

Autor Tema:  Problema con code  (Leído 671 veces)

Wao

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Problema con code
« en: Domingo 14 de Diciembre de 2008, 05:26 »
0
el problema es al agregar estudiantes a un elemento de la lista1....creo q hay un problema con los punteros  :huh: ......puedo solo agregar alumnos a una carrera....

el code esta medio al lote pq es solo de prueba...

Código: Text
  1.  
  2. typedef struct est{
  3.         char elem[20];
  4.         struct est *next;
  5.         struct est *prev;
  6.         }Alumnos;
  7.  
  8. typedef struct list{
  9.         char elemento[20];
  10.         struct list *next;
  11.         Alumnos *Estudiante;
  12.         }Lista1;
  13.  
  14. int opt,opt2,opt3,i,cont;
  15. Lista1 *cabeza,*nuevo,*p,*muestra,*muestra2,*muestra3;
  16. Alumnos *nuevo2,*p2,*mostrarAL, *cabeza2;
  17. mostrar()
  18. {
  19.       muestra=cabeza;
  20.       while(muestra)
  21.       {
  22.            printf("n Carrera: %s",muestra->elemento);
  23.            muestra=muestra->next;
  24.       }  
  25. }
  26. agregar_u()
  27. {
  28.       nuevo=(Lista1*)malloc(sizeof(Lista1));
  29.       printf("nIngrese Nombre De La Carrerann");
  30.       scanf(" %[^n]",nuevo->elemento);
  31.       if(cabeza==NULL)
  32.       {
  33.            cabeza=nuevo;
  34.            cabeza->next=NULL;
  35.            p=cabeza;
  36.       }else{
  37.            p->next=nuevo;
  38.            nuevo->next=NULL;
  39.            p=nuevo;
  40.       }    
  41. }
  42. agregar_al()
  43. {
  44.      printf("nA Que Carrera Desea Agregarle Alumnos?nn");
  45.      muestra2=cabeza;
  46.      i=1;
  47.      while(muestra2)
  48.      {
  49.               printf("n%d.- %s",i,muestra2->elemento);
  50.               i++;
  51.               muestra2=muestra2->next;                                                          
  52.      }  
  53.      scanf("%d",&opt3);
  54.      muestra2=cabeza;
  55.      for(i=1;i<opt3;i++)
  56.           muestra2=muestra2->next;
  57.      printf("n Ud Eligio La Carrera: %s",muestra2->elemento);    
  58.      printf("nn INGRESAR NUEVO ALUMNOn");
  59.      nuevo2=(Alumnos*)malloc(sizeof(Alumnos));
  60.      printf("n NOMBRE: ");
  61.      scanf(" %[^n]",nuevo2->muestra2->Estudiante->elem);
  62.    
  63.      if(cabeza2==NULL)
  64.      {
  65.                       cabeza2=nuevo2;
  66.                       cabeza2->prev=NULL;
  67.                       cabeza2->next=NULL;
  68.                       p2=cabeza2;
  69.                       muestra2->Estudiante=cabeza2;
  70.      }else{
  71.            p2->next=nuevo2;
  72.            nuevo2->prev=p2;
  73.            nuevo2->next=NULL;
  74.            p2=nuevo2;
  75.      }
  76. }
  77. ver_al()
  78. {
  79.      printf("nEn Que Carrera Desea Ver Alumnos?nn");
  80.      muestra3=cabeza;
  81.      i=1;
  82.      while(muestra3)
  83.      {
  84.               printf("n%d.- %s",i,muestra3->elemento);
  85.               i++;
  86.               muestra3=muestra3->next;                                                          
  87.      }  
  88.      scanf("%d",&opt3);
  89.      muestra3=cabeza;
  90.      for(i=1;i<opt3;i++)
  91.           muestra3=muestra3->next;
  92.      printf("n Ud Eligio Carrera: %s",muestra3->elemento);
  93.      mostrarAL=muestra3->Estudiante;
  94.      while(mostrarAL){
  95.          printf("n ALUMNO: %s",mostrarAL->elem);
  96.          mostrarAL=mostrarAL->next;
  97.      }
  98. }
  99. universidad()
  100. {
  101.     printf("n 1.-Ingersar Nueva Carrera A La Base De Datosn");
  102.     printf("n 2.-Agregar Alumnos A Carreran");
  103.     scanf("%d",&opt2);
  104.     if(opt2==1)
  105.          agregar_u();
  106.     if(opt2==2)
  107.          agregar_al();
  108.          
  109. }
  110. menu(){
  111.       do{
  112.          printf("nn 1.- Ingrese Carrera");
  113.          printf("n 2.- Mostrar Datos");
  114.          printf("n 3.- Ver Alumnosn");
  115.          printf("n 4.- Salirn");
  116.          scanf("%d",&opt);
  117.          if(opt==1)
  118.                 universidad();    
  119.          if(opt==2)
  120.                 mostrar();
  121.          if(opt==3)
  122.                 ver_al();  
  123.       }while(opt!=4);
  124. }    
  125.      
  126. main()
  127. {
  128.       menu();
  129.       system("PAUSE");
  130. }
  131.  
  132.  
  133.