Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
struct listado{
char nombre[15];
char apellidos[25];
int edad;
int phone;
char DNI[20];
char direcion[60];
};
void busc(struct listado agenda[],int cantidad);
void mostrar(struct listado agenda[],int cantidad);
void busc1(struct listado agenda[],int cantidad);
void busc2(struct listado agenda[],int cantidad);
void busc3(struct listado agenda[],int cantidad);
void busc4(struct listado agenda[],int cantidad);
void busc5(struct listado agenda[],int cantidad);
void cambiar(struct listado agenda[],int cantidad);
main()
{
int i,contacto,opcion;
struct listado agenda[20];
char sal;
do
{
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" ###### ### ####### # # # # ####### # # ### ###### #######\n");
printf(" # # # # ## # # # # ## # # # # # # \n");
printf(" # # # # # # # # # # # # # # # # # # \n");
printf(" ###### # ##### # # # # # ##### # # # # # # # # \n");
printf(" # # # # # # # # # # # # # # # # # # \n");
printf(" # # # # # ## # # # # ## # # # # # \n");
printf(" ###### ### ####### # # # ####### # # ### ###### ####### \n");
printf("\n Agenda de Gaurav");
getchar();
system("cls");
printf("\n ******AGEND..........****\n");
printf("\n");
printf(" Menu Principal\n");
printf("\n");
printf(" 1: Introducir los datos.\n");
printf("\n");
printf(" 2: Buscar por nombre.\n");
printf("\n");
printf(" 3: Buscar por apellido.\n");
printf("\n");
printf(" 4: Buscar por edad.\n");
printf("\n");
printf(" 5: Buscar por Telefono.\n");
printf("\n");
printf(" 6: Buscar por DNI.\n");
printf("\n");
printf(" 7: Buscar por Direccion.\n");
printf("\n");
printf(" 8: Ver todos los contactos.\n");
printf("\n");
printf(" 9: Modificar los datos.\n");
printf("\n");
printf(" 10: Salir.\n\n");
printf("---------------------------------------------------------------\n");
printf("\n");
printf("Introdusca la opcion que desea realizar:");
scanf("%d",&opcion);
switch(opcion)
{
case 1:
system("cls");
printf("\n");
printf("Cuantos contactos quieres introducir?:");
scanf("%d",&contacto);
system("cls");
for(i=0;i<contacto;i++){
printf("Datos de contacto numero %d:\n",i+1);
printf("\n");
printf("Introducir el Nombre:");
scanf("%s",&agenda[i].nombre);
printf("Introducir Apellidos:");
scanf("%s",&agenda[i].apellidos);
printf("Introducir Edad:");
scanf("%d",&agenda[i].edad);fflush(stdin);
printf("Introducir Telefono:");
scanf("%d",&agenda[i].phone);fflush(stdin);
printf("Introducir DNI:");
scanf("%s",&agenda[i].DNI);
printf("Introducir Direccion:");
scanf("%s",&agenda[i].direcion);
system("cls");
}
break;
case 2:
busc(agenda,contacto);
break;
case 3:
busc1(agenda,contacto);
break;
case 4:
busc2(agenda,contacto);
break;
case 5:
busc3(agenda,contacto);
break;
case 6:
busc4(agenda,contacto);
break;
case 7:
busc5(agenda,contacto);
break;
case 8:
mostrar(agenda,contacto);
break;
case 9:
system("cls");
printf("Quieres salir?(s/n)");
sal=getch();
break;
}
}while(sal!='s');
getch();
system("cls");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf(" ###### ######## ### ###### #### ### ###### \n");
printf(" ## ## ## ## ## ## ## ## ## ## ## ## ## \n");
printf(" ## ## ## ## ## ## ## ## ## ## \n");
printf(" ## #### ######## ## ## ## ## ## ## ###### \n");
printf(" ## ## ## ## ######### ## ## ######### ## \n");
printf(" ## ## ## ## ## ## ## ## ## ## ## ## ## \n");
printf(" ###### ## ## ## ## ###### #### ## ## ###### \n");
getch();
}
void busc(struct listado agenda[],int cantidad)
{
char opcion;
int x,b,c,d;
char cade[15];
system("cls");
printf("Introduzca el nombre:");
scanf("%s",&cade);
system("cls");
for(c=0,x=0;x<cantidad;x++){
if(strcmp(agenda[x].nombre, cade)== 0)
{
c++;
printf("apellido:%s\n",agenda[x].apellidos);
printf("Edad:%d\n",agenda[x].edad);
printf("Telefono:%d\n",agenda[x].phone);
printf("DNI: %s\n",agenda[x].DNI);
printf("Direccion: %s\n",agenda[x].direcion);
}
else if (strcmp(agenda[x].DNI, cade)== 0)
{
c++;
printf("apellido:%s\n",agenda[x].apellidos);
printf("Edad:%d\n",agenda[x].edad);
printf("Telefono:%d\n",agenda[x].phone);
printf("DNI: %s\n",agenda[x].DNI);
printf("Direccion: %s\n",agenda[x].direcion);
}
}
if(c==0)
{
printf("ERROR.");
}
system("pause");
system("cls");
}
void busc1(struct listado agenda[],int cantidad)
{
char opcion;
int x,t,k,d;
char cade[15];
system("cls");
printf("Introduzca el apellido:");
scanf("%s",&cade);
system("cls");
for(k=0,x=0;x<cantidad;x++){
if(strcmp(agenda[x].apellidos, cade)== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("Edad:%d\n",agenda[x].edad);
printf("Telefono:%d\n",agenda[x].phone);
printf("DNI: %s\n",agenda[x].DNI);
printf("Direccion: %s\n",agenda[x].direcion);
}
else if (strcmp(agenda[x].DNI, cade)== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("Edad:%d\n",agenda[x].edad);
printf("Telefono:%d\n",agenda[x].phone);
printf("DNI: %s\n",agenda[x].DNI);
printf("Direccion: %s\n",agenda[x].direcion);
}
}
if(k==0)
{
printf("ERROR.");
}
system("pause");
system("cls");
}
void busc2(struct listado agenda[],int cantidad)
{
char opcion;
int x,t,k,d;
int cade[15];
system("cls");
printf("Introduzca el edad:");
scanf("%s",&cade);
system("cls");
for(k=0,x=0;x<cantidad;x++){
if(strcmp(agenda[x].edad, cade)== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("apellido:%s\n",agenda[x].apellidos);
printf("Telefono:%d\n",agenda[x].phone);
printf("DNI: %s\n",agenda[x].DNI);
printf("Direccion: %s\n",agenda[x].direcion);
}
else if (agenda[x].DNI, cade== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("apellido:%s\n",agenda[x].apellidos);
printf("Telefono:%d\n",agenda[x].phone);
printf("DNI: %s\n",agenda[x].DNI);
printf("Direccion: %s\n",agenda[x].direcion);
}
}
if(k==0)
{
printf("ERROR");
}
system("pause");
system("cls");
}
void busc3(struct listado agenda[],int cantidad)
{
char opcion;
int x,t,k,d;
char cade[15];
system("cls");
printf("Introduzca el numero de telefono: ");
scanf("%d",&cade);
system("cls");
for(k=0,x=0;x<cantidad;x++){
if (agenda[x].phone, cade== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("apellido:%s\n",agenda[x].apellidos);
printf("Edad:%d\n",agenda[x].edad);
printf("DNI: %s\n",agenda[x].DNI);
printf("Direccion: %s\n",agenda[x].direcion);
}
else if (strcmp(agenda[x].DNI, cade)== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("apellido:%s\n",agenda[x].apellidos);
printf("Edad:%d\n",agenda[x].edad);
printf("DNI: %s\n",agenda[x].DNI);
printf("Direccion: %s\n",agenda[x].direcion);
}
}
if(k==0)
{
printf("ERROR");
}
system("pause");
system("cls");
}
void busc4(struct listado agenda[],int cantidad)
{
char opcion;
int x,t,k,d;
char cade[15];
system("cls");
printf("Introduzca el DNI:");
scanf("%s",&cade);
system("cls");
for(k=0,x=0;x<cantidad;x++){
if(strcmp(agenda[x].DNI, cade)== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("apellido:%s\n",agenda[x].apellidos);
printf("Edad:%d\n",agenda[x].edad);
printf("Telefono:%d\n",agenda[x].phone);
printf("Direccion: %s\n",agenda[x].direcion);
}
else if (strcmp(agenda[x].DNI, cade)== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("apellido:%s\n",agenda[x].apellidos);
printf("Edad:%d\n",agenda[x].edad);
printf("Telefono:%d\n",agenda[x].phone);
printf("Direccion: %s\n",agenda[x].direcion);
}
}
if(k==0)
{
printf("ERROR");
}
system("pause");
system("cls");
}
void busc5(struct listado agenda[],int cantidad)
{
char opcion;
int x,t,k,d;
char cade[15];
system("cls");
printf("Introduzca el direccion:");
scanf("%s",&cade);
system("cls");
for(k=0,x=0;x<cantidad;x++){
if(strcmp(agenda[x].direcion, cade)== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("apellido:%s\n",agenda[x].apellidos);
printf("Edad:%d\n",agenda[x].edad);
printf("Telefono:%d\n",agenda[x].phone);
printf("DNI: %s\n",agenda[x].DNI);
}
else if (strcmp(agenda[x].DNI, cade)== 0)
{
k++;
printf("Nombre:%s",agenda[x].nombre);
printf("apellido:%s\n",agenda[x].apellidos);
printf("Edad:%d\n",agenda[x].edad);
printf("Telefono:%d\n",agenda[x].phone);
printf("DNI: %s\n",agenda[x].DNI);
}
}
if(k==0)
{
printf("ERROR");
}
system("pause");
system("cls");
}
void cambiar(struct listado agenda[],int cantidad)
{
int conta,i;
printf("Estos son los contactos:\n");
for(i=0;i<cantidad;i++){
printf("#%d %s\n",i+1,agenda[i].nombre);
}
system("\n");
printf("Introdusca el # del contacto a modificar:");
scanf("%d",&conta);
printf("Ahora modifique el campo que desee.\n");
printf("Contacto # %d \n",i+1);
printf("Introdusca Nombre:");
scanf("%s",&agenda[conta-1].nombre);
printf("Introdusca Apellidos:");
scanf("%s",&agenda[conta-1].apellidos);
printf("Introdusca Edad:");
scanf("%d",&agenda[conta-1].edad);fflush(stdin);
printf("Introdusca Telefono:");
scanf("%d",&agenda[conta-1].phone);fflush(stdin);
printf("Introdusca DNI:");
scanf("%s",&agenda[conta-1].DNI);
printf("Introdusca Direccion:");
scanf("%s",&agenda[conta-1].direcion);
system("pause");
}
void mostrar(struct listado agenda[],int cantidad)
{
int i;
system("cls");
printf("Los contactos almacenados son:\n");
for(i=0;i<cantidad;i++){
printf("Nombre:%s %s \nEdad:%d \nTelefono:%d \nDNI:%s\nDireccion:%s \n",agenda[i].nombre,agenda[i].apellidos,agenda[i].edad,agenda[i].phone,agenda[i].DNI,agenda[i].direcion);
printf("***************************************************\n");
}
system("pause");
}