Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct _agenda {
- char nombre[20];
- char telefono[12];
- char equipo[20];
- struct _agenda *siguiente;
- };
- struct _agenda *primero, *ultimo;
- void mostrar_menu() {
- system("cls");
- printf("\n\nMenu:\n=====\n\n");
- printf("1.- Agregar elementos\n");
- printf("2.- Borrar elementos\n");
- printf("3.- Mostrar contacto\n");
- printf("4.- Salir\n\n");
- printf("Escoge una opcion: ");fflush(stdout);
- }
- void anadir_elemento() {
- struct _agenda *nuevo;
- /* reservamos memoria para el nuevo elemento */
- nuevo = (struct _agenda *) malloc(sizeof(struct _agenda));
- if (nuevo==NULL) printf( "No hay memoria disponible!\n");
- printf("\nNuevo elemento:\n");
- printf("Nombre: "); fflush(stdout);
- gets(nuevo->nombre);
- printf("Telefono: "); fflush(stdout);
- gets(nuevo->telefono);
- printf("Equipo: "); fflush(stdout);
- gets(nuevo->equipo);
- /* el campo siguiente va a ser NULL por ser el último elemento
- de la lista */
- nuevo->siguiente = NULL;
- if (primero==NULL) {
- printf( "Primer elemento\n");
- primero = nuevo;
- ultimo = nuevo;
- }
- else {
- /* el que hasta ahora era el último tiene que apuntar al nuevo */
- ultimo->siguiente = nuevo;
- /* hacemos que el nuevo sea ahora el último */
- ultimo = nuevo;
- }
- }
- void mostrar_lista() {
- struct _agenda *auxiliar;
- int i;
- i=0;
- auxiliar = primero;
- printf("\nMostrando la lista completa:\n");
- while (auxiliar!=NULL) {
- printf( "Nombre: %s \n Telefono: %s \n equipo: %s\n",
- auxiliar->nombre,auxiliar->telefono,auxiliar->equipo);
- auxiliar = auxiliar->siguiente;
- i++;
- }
- if (i==0) printf( "\nLa agenda esta vacia!!\n" );
- }
- void mostrar_magallanes() {
- int x;
- printf("\nLos contacto magallaneros son: \n");
- for(x=0; x < 5; x++)
- {
- if(strcmp(auxiliar->equipo[x],"caraquista") == 0)
- {
- printf("los contactos caraquista son");
- printf("\nEl nombre es: %s \n",auxiliar.nombre[x]);
- printf ("el telefono: %s \n",auxiliar.telefono[x]);
- }
- }
- }
- void borrar_elemento(){
- free(primero=NULL);
- }
- int main() {
- char opcion;
- primero = (struct _agenda *) NULL;
- ultimo = (struct _agenda *) NULL;
- do {
- mostrar_menu();
- opcion = getch();
- switch ( opcion ) {
- case '1': anadir_elemento();
- break;
- case '2': borrar_elemento();
- break;
- case '3': mostrar_lista(primero);
- break;
- case '2': mostrar_magallanes();
- break;
- case '5': exit( 1 );
- default: printf( "Opción no válida\n" );
- break;
- }
- } while (opcion!='4');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement