Advertisement
attackers

Untitled

Nov 24th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.19 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  struct _agenda {
  4.         char nombre[20];
  5.         char telefono[12];
  6.         char equipo[20];
  7.         struct _agenda *siguiente;
  8.         };
  9.  
  10.  struct _agenda *primero, *ultimo;
  11.  
  12.  void mostrar_menu() {
  13.       system("cls");
  14.       printf("\n\nMenu:\n=====\n\n");
  15.       printf("1.- Agregar elementos\n");
  16.       printf("2.- Borrar elementos\n");
  17.       printf("3.- Mostrar contacto\n");
  18.       printf("4.- Salir\n\n");
  19.       printf("Escoge una opcion: ");fflush(stdout);
  20.  }
  21.  
  22.  void anadir_elemento() {
  23.       struct _agenda *nuevo;
  24.  
  25.       /* reservamos memoria para el nuevo elemento */
  26.       nuevo = (struct _agenda *) malloc(sizeof(struct _agenda));
  27.       if (nuevo==NULL) printf( "No hay memoria disponible!\n");
  28.  
  29.       printf("\nNuevo elemento:\n");
  30.       printf("Nombre: "); fflush(stdout);
  31.       gets(nuevo->nombre);
  32.       printf("Telefono: "); fflush(stdout);
  33.       gets(nuevo->telefono);
  34.       printf("Equipo: "); fflush(stdout);
  35.       gets(nuevo->equipo);
  36.  
  37.       /* el campo siguiente va a ser NULL por ser el último elemento
  38.          de la lista */
  39.       nuevo->siguiente = NULL;
  40.  
  41.  
  42.       if (primero==NULL) {
  43.          printf( "Primer elemento\n");
  44.          primero = nuevo;
  45.          ultimo = nuevo;
  46.          }
  47.       else {
  48.            /* el que hasta ahora era el último tiene que apuntar al nuevo */
  49.            ultimo->siguiente = nuevo;
  50.            /* hacemos que el nuevo sea ahora el último */
  51.            ultimo = nuevo;
  52.       }
  53.  }
  54.  
  55.  
  56.  
  57.  void mostrar_lista() {
  58.       struct _agenda *auxiliar;
  59.       int i;
  60.  
  61.       i=0;
  62.       auxiliar = primero;
  63.       printf("\nMostrando la lista completa:\n");
  64.       while (auxiliar!=NULL) {
  65.             printf( "Nombre: %s \n Telefono: %s \n equipo: %s\n",
  66.                     auxiliar->nombre,auxiliar->telefono,auxiliar->equipo);
  67.             auxiliar = auxiliar->siguiente;
  68.             i++;
  69.       }
  70.       if (i==0) printf( "\nLa agenda esta vacia!!\n" );
  71.  }
  72.  
  73.  
  74.  
  75.  void mostrar_magallanes() {
  76.  
  77.       int x;
  78.      
  79.       printf("\nLos contacto magallaneros son: \n");
  80.      
  81.       for(x=0; x < 5; x++)
  82.           {
  83.       if(strcmp(auxiliar->equipo[x],"caraquista") == 0)
  84.          {
  85.         printf("los contactos caraquista son");
  86.     printf("\nEl nombre es: %s \n",auxiliar.nombre[x]);
  87.     printf ("el telefono: %s  \n",auxiliar.telefono[x]);
  88.    
  89.            }
  90.            }
  91.            }
  92.  
  93.  
  94. void borrar_elemento(){
  95.  
  96.   free(primero=NULL);
  97.  
  98.                      }
  99.  
  100.  
  101.  int main() {
  102.      char opcion;
  103.  
  104.      primero = (struct _agenda *) NULL;
  105.      ultimo = (struct _agenda *) NULL;
  106.      do {
  107.          mostrar_menu();
  108.          opcion = getch();
  109.              switch ( opcion ) {
  110.                 case '1': anadir_elemento();
  111.                        break;
  112.                 case '2':  borrar_elemento();
  113.                         break;
  114.                 case '3': mostrar_lista(primero);
  115.                         break;
  116.                        
  117.                 case '2': mostrar_magallanes();
  118.                 break;
  119.                
  120.                 case '5': exit( 1 );
  121.                 default: printf( "Opción no válida\n" );
  122.                          break;
  123.              }
  124.      } while (opcion!='4');
  125.  }
  126.  
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement