#include<stdio.h>
#include<conio.h>
#include<string.h>
int count=0;
struct address_book
{
char name[30];
long bday;
int age;
int number;
char street[20];
char brgy[20];
char city[20];
int zip;
}list[9];
main()
{
int x;
clrscr();
for(x=0; x<9; x++)
{
clrscr();
printf("\n Entry no. %d",x+1);
printf("\n Name : ");
scanf("%s",&list[x].name);
printf(" Birthday : ");
scanf("%li",&list[x].bday);
printf(" Age : ");
scanf("%d",&list[x].age);
printf("\n ADDRESS: Number : ");
scanf("%i",&list[x].number);
printf("\n Street : ");
scanf("%s",&list[x].street);
printf(" Brgy. : ");
scanf("%s",&list[x].brgy);
printf(" City : ");
scanf("%s",&list[x].city);
printf(" Zip : ");
scanf("%i",&list[x].zip);
printf("\n\n Contents for entry %d complete!",x+1);
printf("\n Press any key to proceed to the next entry...");
getch();
}
show();
}
show()
{
int x, y, row, col;
clrscr();
row=1;
for(x=0; x<3; x++)
{
col=1;
for(y=0; y<3; y++)
{
gotoxy(col,row);
printf(" ENTRY %d",count+1);
gotoxy(col,row+1);
printf(" Name : %s",list[count].name);
gotoxy(col,row+2);
printf(" Birthday: %li",list[count].bday);
gotoxy(col,row+3);
printf(" Age : %d",list[count].age);
gotoxy(col,row+4);
printf(" ADDRESS: No.: %d",list[count].number);
gotoxy(col,row+5);
printf(" Street : %s",list[count].street);
gotoxy(col,row+6);
printf(" Brgy : %s",list[count].brgy);
gotoxy(col,row+7);
printf(" City : %s",list[count].city);
gotoxy(col,row+8);
printf(" Zip : %d",list[count].zip);
col=col+26;
count=count++;
}
row=row+8;
}
getch();
main2();
}
main2()
{
char choice;
clrscr();
printf("\n What do you want to do\?\n");
printf("\n [1] Search");
printf("\n [2] Exit");
printf("\n > ");
choice=getch();
switch(choice)
{
case '1':
search();
case '2':
exit();
default:
main2();
}
}
search()
{
int x;
char search[30], search_name[9];
char search_street[9], search_brgy[9];
char search_city[9];
clrscr();
printf("\n SEARCH ENTRY \n");
printf("\n Enter entry keyword: ");
scanf("%s",&search);
printf("\n\n searching database...");
for(x=0; x<10; x++)
{
if(!strcmp(search,list[x].name))
{
search_name[x]=1;
}
if(!strcmp(search,list[x].street))
{
search_street[x]=1;
}
if(!strcmp(search,list[x].brgy))
{
search_brgy[x]=1;
}
if(!strcmp(search,list[x].city))
{
search_city[x]=1;
}
}
clrscr();
printf("\n RESULTS BELOW:");
for(x=0; x<9;x++)
{
if(search_name[x]==1)
{
printf("\n Result found on entry %d on the 'Name' field.",x+1);
}
if(search_street[x]==1)
{
printf("\n Result found on entry %d on the 'Street' field.",x+1);
}
if(search_brgy[x]==1)
{
printf("\n Result found on entry %d on the 'Brgy' field.",x+1);
}
if(search_city[x]==1)
{
printf("\n Result found on entry %d on the 'City' field.",x+1);
}
}
printf("\n\n\n Press any key to go back to Menu...");
getch();
main2();
}
|