Aise Hi
Aise Hi
Aise Hi
#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<stdlib.h>
struct subscriber
char phonenumber[20];
char name[50];
float amount;
}s;
//void gotoxy(int,int);
void addrecords();
void listrecords();
void modifyrecords();
void deleterecords();
void searchrecords();
void payment();
//void login();
char get;
int main()
{ int password;
int phonenumber;
char choice;
system("cls");
printf("\n\n\n\n\n\n\n\n\n**************************************************************"
);
printf("\n\t\t****************************************************************");
Sleep(2000);
getch();
system("cls");
while (1)
system("cls");
choice=getche();
choice=toupper(choice);
switch(choice)
case 'P':
payment();break;
case 'A':
addrecords();break;
case 'L':
listrecords();break;
case 'M':
modifyrecords();break;
case 'S':
searchrecords();break;
case 'D':
deleterecords();break;
case 'E':
system("cls");
printf("\n\n\t\t\t\tTHANK YOU");
Sleep(2000);
exit(0);
break;
default:
system("cls");
printf("Incorrect Input");
getch();
}
}
void addrecords()
FILE *f;
char test;
f=fopen("pro.txt","ab+");
if(f==0)
{ f=fopen("pro.txt","wb+");
system("cls");
getch();
while(1)
system("cls");
scanf("%s",&s.phonenumber);
fflush(stdin);
scanf("%s",&s.name);
scanf("%f",&s.amount);
fwrite(&s,sizeof(s),1,f);
fflush(stdin);
printf("\n Press esc Key to exit or Press any other key to add other record:");
test=getche();
if(test==27)
break;
fclose(f);
system("cls");
void listrecords()
FILE *f;
int i;
if((f=fopen("pro.txt","rb"))==NULL)
exit(0);
system("cls");
for(i=0;i<79;i++)
printf("-");
while(fread(&s,sizeof(s),1,f)==1)
printf("\n");
for(i=0;i<79;i++)
printf("-");
fclose(f);
getch();
system("cls");
void deleterecords()
FILE *f,*t;
char phonenumber[20];
system("cls");
f=fopen("pro.txt","rb+");
t=fopen("pro1.txt","wb+");
do{
rewind(f);
scanf("%s",phonenumber);
while(fread(&s,sizeof(s),1,f)==1)
if(strcmp(s.phonenumber,phonenumber)!=0)
{ fwrite(&s,sizeof(s),1,t);
}
else
fclose(f);
fclose(t);
remove("pro.txt");
rename("pro1.txt","pro.txt");
f=fopen("pro.txt","rb+");
t=fopen("pro1.txt","wb+");
fflush(stdin);
while(getche()=='y'||getche()=='Y');
fclose(f);
getch();
system("cls");
void searchrecords()
FILE *f;
char phonenumber[20];
int flag=1;
f=fopen("pro.txt","rb+");
fflush(stdin);
system("cls");
scanf("%s", phonenumber);
while(fread(&s,sizeof(s),1,f)==1)
if(strcmp(s.phonenumber,phonenumber)==0)
{ system("cls");
flag=0;
break;
else if(flag==1)
{ system("cls");
getch();
fclose(f);
system("cls");
void modifyrecords()
{
FILE *f;
char phonenumber[20];
if((f=fopen("pro.txt","rb+"))==NULL)
exit(0);
system("cls");
scanf("%s",phonenumber);
fflush(stdin);
while(fread(&s,sizeof(s),1,f)==1)
if(strcmp(s.phonenumber,phonenumber)==0)
system("cls");
scanf("%s",&s.phonenumber);
fflush(stdin);
scanf("%[^\n]",&s.name);
scanf("%f",&s.amount);
fseek(f,-size,SEEK_CUR);
fwrite(&s,sizeof(s),1,f);
break;
}
}
fclose(f);
system("cls");
void payment()
FILE *f;
char phonenumber[20];
float amt;
int i;
if((f=fopen("pro.txt","rb+"))==NULL)
exit(0);
system("cls");
scanf("%s",phonenumber);
fflush(stdin);
while(fread(&s,sizeof(s),1,f)==1)
if(strcmp(s.phonenumber,phonenumber)==0)
printf("\n ***DETAILS***");
for(i=0;i<79;i++)
printf("-");
fflush(stdin);
scanf(" %f",&amt);
s.amount=s.amount-amt;
fseek(f,-size,SEEK_CUR);
fwrite(&s,sizeof(s),1,f);
break;
printf("\n\n");
getch();
fclose(f);
system("cls");