Code for telephone directory in c
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<time.h>
struct teledir
{
char firstname[50];
char lastname[50];
char address[50];
char landline[15];
char mobile[15];
}td;
struct signup
{
char firstname[20];
char lastname[20];
char email[50];
char password[20];
}s;
int f=0,ls=0;
char em[50];
void gotoxy(int x,int y)
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void SetColorAndBackground(int ForgC, int BackC)
{
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void rectangle(int x, int y, int l, int b)
{
int i,j;
gotoxy(x,y);
printf("%c",201);
for(i=x+1;i<l-1;i++)
{
printf("%c",205);
}
gotoxy(x,y+1);
for(i=y+1;i<b-1;i++)
{
gotoxy(x,i);
printf("%c",186);
}
gotoxy(x,b-1);
printf("%c",200);
gotoxy(x+1,b-1);
for(i=x+1;i<l-1;i++)
{
printf("%c",205);
}
printf("%c",188);
gotoxy(l-1,y);
printf("%c",187);
gotoxy(l-1,y+1);
for(i=y+1;i<b-1;i++)
{
gotoxy(l-1,i);
printf("%c",186);
}
}
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
void animation(char *anm,int a,int b)
{
int i;
for(i=0;i<strlen(anm);i++)
{
delay(150);
gotoxy(a+i,b);
printf("%c",*(anm+i));
}
}
void wait()
{
int i;
printf("PLEASE WAIT...");
for(i=0;i<10;i++)
{
delay(100);
printf(".");
}
}
void readnum(char *word)
{
int i=0;
word[i] = getch();
while(word[i]!='\r')
{
if(word[i]=='\b')
{
printf("\b \b");
i--;
}
else if((word[i]>=48&&word[i]<=57)||(word[i]=='+')||(word[i]=='-')||(word[i]=='*')||(word[i]=='#'))
{
printf("%c",word[i]);
i++;
}
word[i]=getch();
}
word[i]='\0';
}
void upsign()
{
FILE *fp,*tdr;
char first[50],last[50];
int c=0;
system("cls");
do
{
c=0;
fp=fopen("id.txt","ab+");
if(fp==NULL)
{
printf("Can't access the desired file.....");
}
SetColorAndBackground(14,16);
rectangle(10,10,60,20);
gotoxy(12,12);
printf("ENTER YOUR FIRST NAME : ");
gets(first);
fflush(stdin);
gotoxy(12,14);
printf("ENTER YOUR LAST NAME : ");
gets(last);
fflush(stdin);
gotoxy(12,16);
printf("ENTER UNIQUE USERNAME : ");
gets(em);
while(fread(&s,sizeof(s),1,fp)==1)
{
if(strcmp(s.email,em)==0)
{
c++;
}
}
if(c!=0)
{
gotoxy(12,31);
printf("ALREADY EXISTS......");
getch();
system("cls");
continue;
}
strcpy(s.email,em);
fflush(stdin);
gotoxy(12,18);
printf("ENTER PASSSWORD : ");
readpass(s.password);
strcpy(s.firstname,first);
strcpy(s.lastname,last);
fflush(stdin);
fwrite(&s,sizeof(s),1,fp);
tdr=fopen(em,"ab+");
}while(c!=0);
fclose(fp);
fclose(tdr);
}
void inlog()
{
FILE *fp,*tdr;
int flag=1;
char ch,pass[20],x;
system("cls");
fp=fopen("id.txt","ab+");
if(fp==NULL)
{
printf("Can't access the desired file.....");
}
SetColorAndBackground(9,16);
rectangle(7,7,60,20);
gotoxy(12,10);
printf("ENTER USERNAME : ");
scanf("%s",em);
fflush(stdin);
gotoxy(12,15);
printf("ENTER PASSWORD : ");
readpass(pass);
fflush(stdin);
while(fread(&s,sizeof(s),1,fp)==1)
{
if((strcmp(s.email,em)==0) && (strcmp(s.password,pass)==0))
{
gotoxy(12,21);
wait();
gotoxy(12,22);
printf("\aLOGIN SUCCESSFUL...PRESS ANY KEY......");
getch();
tdr=fopen(em,"ab+");
flag=0;
break;
}
}
if(flag==1)
{
gotoxy(12,22);
printf("\aUSERNAME OR PASSWORD ERROR.....!!!");
getch();
system("cls");
//inlog();
ls=0;
main();
}
fclose(fp);
fclose(tdr);
}
void readpass(char pass[])
{
int i=0;
pass[i]=getch();
while(pass[i]!='\r')
{
if(pass[i]=='\b')
{
printf("\b \b");
i--;
}
else if((pass[i]>='a'&&pass[i]<='z')||(pass[i]>='A'&&pass[i]<='Z')||(pass[i]>='0'&&pass[i]<='9'))
{
printf("%c",42);//42 is the ascii value of *
i++;
}
pass[i]=getch();
}
pass[i]='\0';
}
void frontscreen()
{
int i,d=200;
system("cls");
rectangle(0,0,80,24);
gotoxy(30,3); printf("T_");delay(d);
gotoxy(30,3); printf("TE_");delay(d);
gotoxy(30,3); printf("TEL_");delay(d);
gotoxy(30,3); printf("TELE_");delay(d);
gotoxy(30,3); printf("TELEP_");delay(d);
gotoxy(30,3); printf("TELEPH_");delay(d);
gotoxy(30,3); printf("TELEPHO_");delay(d);
gotoxy(30,3); printf("TELEPHON_");delay(d);
gotoxy(30,3); printf("TELEPHONE_");delay(d);
gotoxy(30,3); printf("TELEPHONE _");delay(d);
gotoxy(30,3); printf("TELEPHONE D_");delay(d);
gotoxy(30,3); printf("TELEPHONE DI_");delay(d);
gotoxy(30,3); printf("TELEPHONE DIR_");delay(d);
gotoxy(30,3); printf("TELEPHONE DIRE_");delay(d);
gotoxy(30,3); printf("TELEPHONE DIREC_");delay(d);
gotoxy(30,3); printf("TELEPHONE DIRECT_");delay(d);
gotoxy(30,3); printf("TELEPHONE DIRECTO_");delay(d);
gotoxy(30,3); printf("TELEPHONE DIRECTOR_");delay(d);
gotoxy(30,3); printf("TELEPHONE DIRECTORY");delay(d);
gotoxy(29,4);
for(i=0;i<21;i++)
{
printf("%c",22);
}
gotoxy(33,9);
printf("PROGRAMMED BY ");
gotoxy(31,10);
for(i=0;i<17;i++)
{
printf("%c",196);
}
gotoxy(35,12);
printf("AJAY YADAV");
gotoxy(35,14);
printf("BCE AB 010");
gotoxy(38,16); printf("2070");
gotoxy(28,20);
printf("PRESS ANY KEY TO CONTINUE...");
getch();
}
int menu()
{
int i,choice;
system("cls");
SetColorAndBackground(10,16);
rectangle(0,0,80,24);
animation("MAIN MENU",32,2);
gotoxy(57,1); printf("%c %s %s",16,s.firstname,s.lastname);
gotoxy(30,3); for(i=0;i<13;i++)
printf("%c",196);
gotoxy(20,5); SetColorAndBackground(9,16); printf("1 TO ADD RECORD IN DIRECTORY");
gotoxy(20,7); SetColorAndBackground(10,16); printf("2 TO LIST RECORD IN DIRECTORY");
gotoxy(20,9); SetColorAndBackground(11,16); printf("3 TO MODIFY RECORD IN DIRECTORY");
gotoxy(20,11); SetColorAndBackground(12,16); printf("4 TO DELETE RECORD IN DIRECTORY");
gotoxy(20,13); SetColorAndBackground(13,16); printf("5 TO SEARCH RECORD IN DIRECTORY");
gotoxy(20,15); SetColorAndBackground(14,16); printf("6 TO LOG OUT AND QUIT THE PROGRAMME");
gotoxy(17,16);
for(i=0;i<40;i++)
{
printf("%c",196);
}
gotoxy(17,17);
printf("ENTER YOUR CHOICE : ");
scanf("%d",&choice);
return(choice);
}
void add()
{
FILE *fpointer;char condition=1,color=9;
fpointer = fopen(em,"ab+");
if(fpointer==NULL)
{
printf("ERRROR IN OPENING FILE......\a\a");
}
while(1)
{
fflush(stdin);
system("cls");
SetColorAndBackground(color,16);
rectangle(0,0,80,3);
animation(">> ADD RECORD",23,1);
gotoxy(57,1); printf("%c %s %s",16,s.firstname,s.lastname);
rectangle(5,5,70,22);
gotoxy(9,8);
fflush(stdin);
printf("FIRSTNAME : ");
scanf("%s",td.firstname);
fflush(stdin);
gotoxy(9,10);
printf("LASTNAME : ");
scanf("%s",td.lastname);
fflush(stdin);
gotoxy(9,12);
printf("ADDRESS : ");
scanf("%s",td.address);
fflush(stdin);
gotoxy(9,14);
printf("LANDLINE : ");
readnum(td.landline);
fflush(stdin);
gotoxy(9,16);
printf("MOBILE : ");
readnum(td.mobile);
fflush(stdin);
fwrite(&td,sizeof(td),1,fpointer);
fflush(stdin);
gotoxy(9,18);
printf("ENTER ESC KEY TO EXIT AND ANY KEY TO INPUT MORE DATA : ");
condition=getche();
if(condition==27) //27 is ascii value of esc
{
gotoxy(9,24);
break;
}
color++;
if(color>=14)
{
color=9;
}
}
fclose(fpointer);
}
void list()
{
FILE *fpointer; int i=7,j,record=0,color=9;
system("cls");
SetColorAndBackground(11,16);
rectangle(0,0,80,3);
animation(">> LIST OF RECORD",2,1);
gotoxy(57,1); printf("%c %s %s",16,s.firstname,s.lastname);
fpointer=fopen(em,"rb");
if(fpointer==NULL)
{
printf("Can't access.....");
}
SetColorAndBackground(14,16);
gotoxy(2,5); printf("FIRST NAME");
gotoxy(17,5); printf("LAST NAME");
gotoxy(32,5); printf("ADDRESS");
gotoxy(47,5); printf("LANDLINE");
gotoxy(62,5); printf("MOBILE");
gotoxy(1,6);
for(j=0;j<78;j++)
{
printf("%c",205);
}
while(fread(&td,sizeof(td),1,fpointer)==1)
{
SetColorAndBackground(color,16);
fflush(stdin);
gotoxy(2,i);
printf("%s",td.firstname);
fflush(stdin);
gotoxy(17,i);
printf("%s",td.lastname);
fflush(stdin);
gotoxy(32,i);
printf("%s",td.address);
fflush(stdin);
gotoxy(47,i);
printf("%s",td.landline);
fflush(stdin);
gotoxy(62,i);
printf("%s",td.mobile);
fflush(stdin);
printf("\n ");
for(j=0;j<78;j++)
{
printf("%c",196);
}
i=i+2;
record++;
color++;
if(color>=14)
{
color=9;
}
}
gotoxy(24,1); printf("No. OF RECORDS IS %d",record);
gotoxy(30,record*2+9); printf("PRESS ANY KEY....");
fclose(fpointer);
getch();
}
void search()
{
system("cls");
int i,j,k=6,srch,fr=0,lr=0,ar=0,liner=0,mr=0;
FILE *fpointer; char frstname[50],lstname[50],adrs[50],line[15],mo[15];
system("cls");
fpointer=fopen(em,"rb");
if(fpointer==NULL)
{
printf("ACCESS DENIED.......\a");
}
rectangle(0,0,80,24);
SetColorAndBackground(10,16);
animation("SEARCH MENU",32,2);
gotoxy(57,1); printf("%c %s %s",16,s.firstname,s.lastname);
gotoxy(30,3); for(i=0;i<15;i++)
printf("%c",196);
gotoxy(20,5); printf("1 TO SEARCH THE RECORD BY FIRST NAME");
gotoxy(20,7); printf("2 TO SEARCH THE RECORD BY LAST NAME");
gotoxy(20,9); printf("3 TO SEARCH THE RECORD BY ADDRESS");
gotoxy(20,11); printf("4 TO SEARCH THE RECORD BY LANDLINE");
gotoxy(20,13); printf("5 TO SEARCH THE RECORD BY MOBILE NO.");
gotoxy(20,15); printf("%c OR PRESS OTHER NUM KEY FOLLOWED BY ENTER",5);
gotoxy(17,16);
for(i=0;i<50;i++)
{
printf("%c",196);
}
gotoxy(17,17);
printf("HOW DO YOU WANT TO SERACH ? : ");
scanf("%d",&srch);
if(srch==1)
{
system("cls"); SetColorAndBackground(11,16);
rectangle(0,0,80,3);
gotoxy(20,1); printf("==>> SEARCH BY FIRST NAME");
gotoxy(5,5); rectangle(5,5,60,10);
gotoxy(7,7); printf("ENTER FIRST NAME : ");
scanf("%s",frstname);
system("cls");
while(fread(&td,sizeof(td),1,fpointer)==1)
{
if(strcmp(td.firstname,frstname)==0)
{
gotoxy(2,3); printf("FIRST NAME");
gotoxy(17,3); printf("LAST NAME");
gotoxy(32,3); printf("ADDRESS");
gotoxy(47,3); printf("LANDLINE");
gotoxy(62,3); printf("MOBILE");
gotoxy(1,4);
for(j=0;j<78;j++)
{
printf("%c",205);
}
gotoxy(2,k);
printf("%s",td.firstname);
fflush(stdin);
gotoxy(17,k);
printf("%s",td.lastname);
fflush(stdin);
gotoxy(32,k);
printf("%s",td.address);
fflush(stdin);
gotoxy(47,k);
printf("%s",td.landline);
fflush(stdin);
gotoxy(62,k);
printf("%s",td.mobile);
fflush(stdin);
printf("\n ");
for(j=0;j<78;j++)
{
printf("%c",196);
}
k=k+2;
fr++;
}
}
if(fr==0)
{
rectangle(10,10,60,17);
gotoxy(20,13); printf("\aRECORD NOT FOUND....");
}
gotoxy(19,k+12); printf("TOTAL SEARCH RESULT BY FIRST NAME IS %d",fr);
gotoxy(24,k+14); printf("PRESS ANY KEY ....");getch();
}
if(srch==2)
{
system("cls"); SetColorAndBackground(12,16);
rectangle(0,0,80,3);
gotoxy(20,1); printf("==>> SEARCH BY LAST NAME");
gotoxy(5,5); rectangle(5,5,60,10);
gotoxy(7,7); printf("ENTER LAST NAME : ");
scanf("%s",lstname);
system("cls");
while(fread(&td,sizeof(td),1,fpointer)==1)
{
if(strcmp(td.lastname,lstname)==0)
{
gotoxy(2,3); printf("FIRST NAME");
gotoxy(17,3); printf("LAST NAME");
gotoxy(32,3); printf("ADDRESS");
gotoxy(47,3); printf("LANDLINE");
gotoxy(62,3); printf("MOBILE");
gotoxy(1,4);
for(j=0;j<78;j++)
{
printf("%c",205);
}
gotoxy(2,k);
printf("%s",td.firstname);
fflush(stdin);
gotoxy(17,k);
printf("%s",td.lastname);
fflush(stdin);
gotoxy(32,k);
printf("%s",td.address);
fflush(stdin);
gotoxy(47,k);
printf("%s",td.landline);
fflush(stdin);
gotoxy(62,k);
printf("%s",td.mobile);
fflush(stdin);
printf("\n ");
for(j=0;j<78;j++)
{
printf("%c",196);
}
k=k+2;
lr++;
}
}
if(lr==0)
{
rectangle(10,10,60,17);
gotoxy(20,13); printf("\aRECORD NOT FOUND....");
}
gotoxy(19,k+12); printf("TOTAL SEARCH RESULT BY LAST NAME IS %d",lr);
gotoxy(24,k+14); printf("PRESS ANY KEY ....");getch();
}
if(srch==3)
{
system("cls"); SetColorAndBackground(13,16);
rectangle(0,0,80,3);
gotoxy(20,1); printf("==>> SEARCH BY ADDRESS");
gotoxy(5,5); rectangle(5,5,60,10);
gotoxy(7,7); printf("ENTER ADDRESS : ");
scanf("%s",adrs);
system("cls");
while(fread(&td,sizeof(td),1,fpointer)==1)
{
if(strcmp(td.address,adrs)==0)
{
gotoxy(2,3); printf("FIRST NAME");
gotoxy(17,3); printf("LAST NAME");
gotoxy(32,3); printf("ADDRESS");
gotoxy(47,3); printf("LANDLINE");
gotoxy(62,3); printf("MOBILE");
gotoxy(1,4);
for(j=0;j<78;j++)
{
printf("%c",205);
}
gotoxy(2,k);
printf("%s",td.firstname);
fflush(stdin);
gotoxy(17,k);
printf("%s",td.lastname);
fflush(stdin);
gotoxy(32,k);
printf("%s",td.address);
fflush(stdin);
gotoxy(47,k);
printf("%s",td.landline);
fflush(stdin);
gotoxy(62,k);
printf("%s",td.mobile);
fflush(stdin);
printf("\n ");
for(j=0;j<78;j++)
{
printf("%c",196);
}
k=k+2;
ar++;
}
}
if(ar==0)
{
rectangle(10,10,60,17);
gotoxy(20,13); printf("\aRECORD NOT FOUND....");
}
gotoxy(19,k+12); printf("TOTAL SEARCH RESULT BY ADDRESS IS %d",ar);
gotoxy(24,k+14); printf("PRESS ANY KEY ....");getch();
}
if(srch==4)
{
system("cls"); SetColorAndBackground(14,16);
rectangle(0,0,80,3);
gotoxy(20,1); printf("==>> SEARCH BY LANDLINE");
gotoxy(5,5); rectangle(5,5,60,10);
gotoxy(7,7); printf("ENTER LANDLINE NUMBER : ");
scanf("%s",line);
system("cls");
while(fread(&td,sizeof(td),1,fpointer)==1)
{
if(strcmp(td.landline,line)==0)
{
gotoxy(2,3); printf("FIRST NAME");
gotoxy(17,3); printf("LAST NAME");
gotoxy(32,3); printf("ADDRESS");
gotoxy(47,3); printf("LANDLINE");
gotoxy(62,3); printf("MOBILE");
gotoxy(1,4);
for(j=0;j<78;j++)
{
printf("%c",205);
}
gotoxy(2,k);
printf("%s",td.firstname);
fflush(stdin);
gotoxy(17,k);
printf("%s",td.lastname);
fflush(stdin);
gotoxy(32,k);
printf("%s",td.address);
fflush(stdin);
gotoxy(47,k);
printf("%s",td.landline);
fflush(stdin);
gotoxy(62,k);
printf("%s",td.mobile);
fflush(stdin);
printf("\n ");
for(j=0;j<78;j++)
{
printf("%c",196);
}
k=k+2;
liner++;
}
}
if(liner==0)
{
rectangle(10,10,60,17);
gotoxy(20,13); printf("\aRECORD NOT FOUND....");
}
gotoxy(19,k+12); printf("TOTAL SEARCH RESULT BY LANDLINE IS %d",liner);
gotoxy(24,k+14); printf("PRESS ANY KEY ....");getch();
}
if(srch==5)
{
system("cls"); SetColorAndBackground(9,16);
rectangle(0,0,80,3);
gotoxy(20,1); printf("==>> SEARCH BY MOBILE NUMBER");
gotoxy(5,5); rectangle(5,5,60,10);
gotoxy(7,7); printf("ENTER MOBILE NUMBER : ");
scanf("%s",mo);
system("cls");
while(fread(&td,sizeof(td),1,fpointer)==1)
{
if(strcmp(td.mobile,mo)==0)
{
gotoxy(2,3); printf("FIRST NAME");
gotoxy(17,3); printf("LAST NAME");
gotoxy(32,3); printf("ADDRESS");
gotoxy(47,3); printf("LANDLINE");
gotoxy(62,3); printf("MOBILE");
gotoxy(1,4);
for(j=0;j<78;j++)
{
printf("%c",205);
}
gotoxy(2,k);
printf("%s",td.firstname);
fflush(stdin);
gotoxy(17,k);
printf("%s",td.lastname);
fflush(stdin);
gotoxy(32,k);
printf("%s",td.address);
fflush(stdin);
gotoxy(47,k);
printf("%s",td.landline);
fflush(stdin);
gotoxy(62,k);
printf("%s",td.mobile);
fflush(stdin);
printf("\n ");
for(j=0;j<78;j++)
{
printf("%c",196);
}
k=k+2;
mr++;
}
}
if(mr==0)
{
rectangle(10,10,60,17);
gotoxy(20,13); printf("\aRECORD NOT FOUND....");
}
gotoxy(19,k+12); printf("TOTAL SEARCH RESULT BY MOBILE NUMBER IS %d",mr);
gotoxy(24,k+14); printf("PRESS ANY KEY ...."); getch();
}
fclose(fpointer);
}
void modify()
{
FILE *fpointer,*temp; char mo[15],line[15]; int msrch,chk=0,i;
system("cls");
rectangle(0,0,80,24);
animation("MODIFICATION MENU",32,2);
gotoxy(57,1); printf("%c %s %s",16,s.firstname,s.lastname);
gotoxy(30,3); for(i=0;i<21;i++)
printf("%c",196);
gotoxy(20,5); printf("1 TO MODIFY RECORDS BY MOBILE NUMBER");
gotoxy(20,7); printf("2 TO MODIFY RECORDS BY LANDLINE NUMBER");
gotoxy(20,9); printf("%c OR PRESS OTHER NUM KEY FOLLOWED BY ENTER",16);
gotoxy(17,10);
for(i=0;i<50;i++)
{
printf("%c",196);
}
gotoxy(17,12);
printf("HOW DO YOU WANT TO PREFORM MODIFICATION ? : ");
scanf("%d",&msrch);
system("cls");
fpointer = fopen(em,"rb");
temp=fopen("temp","ab+");
if(fpointer==NULL)
{
printf("ERRROR IN OPENING FILE......\a\a");
}
if(temp==NULL)
{
printf("ERROR IN OPENING FILE.......\a");
}
switch(msrch)
{
case 1:
{
rectangle(0,0,80,3);
gotoxy(20,1); printf("==>> MODIFICATION BY MOBILE NUMBER");
gotoxy(5,5); rectangle(5,5,60,10);
gotoxy(7,7); printf("ENTER MOBILE NUMBER : ");
readnum(mo);//to accept (number,*,#,+,-) as input
system("cls");
while(fread(&td,sizeof(td),1,fpointer)==1)
{
if(strcmp(td.mobile,mo)==0)
{
chk=1; SetColorAndBackground(12,16);
system("cls");
rectangle(0,0,80,3);
gotoxy(20,1); printf("MODIFICATION OF MOBILE NUMBER %s",mo);
rectangle(5,5,70,21);
gotoxy(9,8); fflush(stdin);
printf("FIRSTNAME : ");
scanf("%s",&td.firstname);
fflush(stdin);
gotoxy(9,10);
printf("LASTNAME : ");
gets(td.lastname);
fflush(stdin);
gotoxy(9,12);
printf("ADDRESS : ");
gets(td.address);
fflush(stdin);
gotoxy(9,14);
printf("LANDLINE : ");
readnum(td.landline);
fflush(stdin);
gotoxy(9,16);
printf("MOBILE : ");
readnum(td.mobile);
fflush(stdin);
fwrite(&td,sizeof(td),1,temp);
}
else
{
fwrite(&td,sizeof(td),1,temp);
}
}
fclose(fpointer);
fclose(temp);
remove(em);
rename("temp",em);
if(chk!=0)
{
system("cls");
rectangle(10,10,60,20);
gotoxy(12,12); wait();
gotoxy(15,15); printf("\aRECORD SUCCESSFULLY MODIFIED.....");
gotoxy(17,17); printf("PRESS ANY KEY...");
}
if(chk==0)
{
system("cls");
rectangle(10,10,60,20);
gotoxy(12,12); wait();
gotoxy(15,15); printf("\aRECORD NOT FOUND....");
gotoxy(17,17); printf("PRESS ANY KEY...");
}
break;
}
case 2:
{
rectangle(0,0,80,3);
gotoxy(20,1); printf("==>> MODIFICATION BY LANDLINE NUMBER");
gotoxy(5,5); rectangle(5,5,60,10);
gotoxy(7,7); printf("ENTER LANDLINE NUMBER : ");
readnum(line);//scanf("%s",line);
system("cls");
while(fread(&td,sizeof(td),1,fpointer)==1)
{
if(strcmp(td.landline,line)==0)
{
chk=1; SetColorAndBackground(13,16);
system("cls");
rectangle(0,0,80,3);
gotoxy(20,1); printf("MODIFICATION OF LANDLINE NUMBER %s",line);
rectangle(5,5,70,21);
gotoxy(9,8);
printf("FIRSTNAME : ");
scanf("%s",&td.firstname);
fflush(stdin);
gotoxy(9,10);
printf("LASTNAME : ");
gets(td.lastname);
fflush(stdin);
gotoxy(9,12);
printf("ADDRESS : ");
gets(td.address);
fflush(stdin);
gotoxy(9,14);
printf("LANDLINE : ");
readnum(td.landline);
fflush(stdin);
gotoxy(9,16);
printf("MOBILE : ");
readnum(td.mobile);
fflush(stdin);
fwrite(&td,sizeof(td),1,temp);
}
else
{
fwrite(&td,sizeof(td),1,temp);
}
}
fclose(fpointer);
fclose(temp);
remove(em);
rename("temp",em);
if(chk!=0)
{
system("cls");
rectangle(10,10,60,20);
gotoxy(12,12); wait();
gotoxy(15,15); printf("\aRECORD SUCCESSFULLY MODIFIED.....");
gotoxy(17,17); printf("PRESS ANY KEY...");
}
if(chk==0)
{
system("cls");
rectangle(10,10,60,20);
gotoxy(12,12); wait();
gotoxy(15,15); printf("\aRECORD NOT FOUND....");
gotoxy(17,17); printf("PRESS ANY KEY...");
}
break;
}
default:
{
system("cls");
main();
break;
}
}
getch();
}
void del()
{
FILE *fpointer,*temp; char fname[50],mo[15],ch;int dsrch,i,check=0;
system("cls"); SetColorAndBackground(9,16);
rectangle(0,0,80,24);
animation("DELETE MENU",32,2);
gotoxy(57,1); printf("%c %s %s",16,s.firstname,s.lastname);
gotoxy(30,3); for(i=0;i<15;i++)
printf("%c",196);
gotoxy(20,5); printf("1 TO DELETE SELECTIVE RECORDS");
gotoxy(20,7); printf("2 TO DELETE ALL RECORDS");
gotoxy(20,9); printf("%c OR PRESS OTHER NUM KEY FOLLOWED BY ENTER",4);
gotoxy(17,10);
for(i=0;i<50;i++)
{
printf("%c",196);
}
gotoxy(17,12);
printf("HOW DO YOU WANT TO PREFORM DELETION ? : ");
scanf("%d",&dsrch);
system("cls");
if(dsrch==1)
{
fpointer = fopen(em,"rb");
temp=fopen("temp","ab+");
if(fpointer==NULL)
{
printf("ERRROR IN OPENING FILE......\a\a");
}
if(temp==NULL)
{
printf("ERROR IN OPENING FILE.......\a");
}
SetColorAndBackground(11,16);
rectangle(0,0,80,3);
gotoxy(20,1); printf("==>> SELECTIVE DELETION");
gotoxy(5,5); rectangle(5,5,60,15);
gotoxy(7,7); printf("ENTER FIRST NAME : ");
scanf("%s",fname);
gotoxy(7,10); printf("ENTER MOBILE NUMBER : ");
readnum(mo);
system("cls");
while(fread(&td,sizeof(td),1,fpointer)==1)
{
if((strcmp(td.firstname,fname)==0) && (strcmp(td.mobile,mo)==0))
{
check++;
continue;
}
else
{
fwrite(&td,sizeof(td),1,temp);
}
}
fclose(fpointer);
fclose(temp);
remove(em);
rename("temp",em);
if(check!=0)
{
rectangle(10,10,60,20);
gotoxy(12,12); wait();
gotoxy(15,15); printf("\aRECORD SUCCESSFULLY DELETED.....");
gotoxy(17,17); printf("PRESS ANY KEY...");
getch();
}
if(check==0)
{
rectangle(10,10,60,20);
gotoxy(12,12); wait();
gotoxy(15,15); printf("\aRECORD NOT FOUND....");
gotoxy(17,17); printf("PRESS ANY KEY...");
getch();
}
}
if(dsrch==2)
{
system("cls"); SetColorAndBackground(12,16);
rectangle(10,10,65,15);
gotoxy(12,12);
printf("ARE YOU SURE YOU WANT TO CLEAR ALL RECORDS ? ");
if(getche()=='y' || getche()=='Y')
{
getch();
system("cls");
fpointer = fopen(em,"rb");
temp=fopen(em,"ab+");
if(fpointer==NULL)
{
printf("ERRROR IN OPENING FILE......\a\a");
}
if(temp==NULL)
{
printf("ERROR IN OPENING FILE.......\a");
}
fclose(fpointer);
fclose(temp);
remove(em);
rename("temp",em);
rectangle(10,10,60,20);
gotoxy(12,12); wait();
gotoxy(15,15); printf("\aRECORD SUCCESSFULLY DELETED.....");
gotoxy(17,17); printf("PRESS ANY KEY...");
getch();
}
}
else
{
main();
}
}
void end()
{
system("cls");
SetColorAndBackground(12,16);
rectangle(12,7,60,15);
gotoxy(14,9); printf("PRESS SPACE BAR TO RETURN TO PROGRAM");
gotoxy(15,12); printf("OR ANY OTHER KEY TO END.....");
gotoxy(17,17);
if(getch()==32)
main();
else
exit(0);
}
void main()
{
int mchoice;char x;
if(f==0)
{
frontscreen();
f++;
system("cls");
}
if(ls==0)
{
SetColorAndBackground(13,16);
rectangle(25,7,60,15);
gotoxy(28,9); printf("1 FOR LOG IN");
gotoxy(28,12); printf("2 FOR SIGN UP");
gotoxy(25,20);
x=getche();
switch(x)
{
case '1':
{
inlog();
break;
}
case '2':
{
upsign();
break;
}
}
ls++;
}
mchoice=menu();
switch(mchoice)
{
case 1:
{
add();
main();
break;
}
case 2:
{
list();
main();
break;
}
case 3:
{
modify();
main();
break;
}
case 4:
{
del();
main();
break;
}
case 5:
{
search();
main();
break;
}
case 6:
{
end();
break;
}
default:
{
main();
break;
}
}
getch();
}
0 comments:
Post a Comment