Hi there every body, i am trying to build this contact list to hold records for a purpoted library but i got a little stuck with a few issues that i would like you guys to look at. The fifth switch(delete) statement does behave strangely i should say. When I start the program and delete a record, it shows the record is deleted when you check via the view item on the menu. But should I restart the program, the record deleted resurfaces among other records(it is more of deleting a record temporarily in my view which is not what intend of course). I am not sure if it is because of the model i have used to construct the code or otherwise but i wanted to try using something other than using functions for the main items as used in the switch statement. if someone has experienced the same scenrio, i would like to know how i can fix this with their help
I was trying to do some real validation but hit the wall in some areas. On lines 42 and 43, i declared two variables of type char and initialised them as you can see. My intention was to try to validate an email entered by the user as you can see but i realise the thing isn't working as I expected.
Look at lines 132-140, i was trying to find characters other than alphabets but it couldnn't work out too.Someone more comfortable with this can give a hand.
The other thing perhaps i need help with is how I can make every id number unique so i can use this to query the database for a particular record. I did try to start up something from line 435-447 but soon ran out of ideas.
The last issue is with the entire program itself in the way it responds. When I select an item, say view records, it does so well. But should I return to the menu from there and select another operation like modify or delete record, it starts behaving strangely like it will skip everything and display the last message like "Do you want to modify another record" or "Do you want to delete another record". I am not sure really why this is happening. You guys out there do advise me and comment on the general program, design, logic and any other thing you feel needs to be altered.
Many thanks in advance and am looking forward to your responses
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
/* prototypes of functions used in the program*/
void menu(void);
void fname(void);
void lname(void);
void id(void);
void age(void);
void gender(void);
void email(void);
void tel_no(void);
void address(void);
void doj(void);
/*declaration of global variables*/
int chk,f,t,x,d,m,y,ID,choice;
/*structure to hold member details*/
struct customer
{
char id[4][4];
char dd[2][3],mth[2][3],yr[4][5];
char l_name[9][9];
char f_name[9][9];
char gender[2][3];
char age[2][2];
char doj[10][10];
char address[25][25];
char tel_num[12][12];
char email[15][15];
}customer_rec;
char *ser1,*ser2;
char ser='@';
char ser0='.';
void main(void)
{
FILE*ltlsys,*tempdb; /*names of files that shall be used in the program*/
char again1;
char save_rec;
char access1[6]="lu23ad"; /*password for entering the program*/
int choice2,chc=0,trk=0;
long int datsize; /* size of the entire file(ltlsys)*/
char fname2[9]; /*shall be used to query the database*/
/* loop to test password to access the rest of the program*/
while(chc<3)
{
clrscr();
gotoxy(22,7);
printf("WELCOME TO LENNYSVILLE LIBRARY DATABASE");
gotoxy(28,11);
printf("Please,enter your password: ");
gets(access1);
if(strcmp(access1,"lu23ad")!=0)
{
gotoxy(22,21);
printf("You entered an invalid password!");
gotoxy(22,23);
printf(" Please try again");
getch();
clreol();
chc++;
}
else
{ /*open file for read/write operations*/
ltlsys = fopen ( "\\LIBUSER.DAT", "rb+" );
if ( ltlsys == NULL )
{
ltlsys = fopen ( "\\LIBUSER.DAT","wb+" );
if ( ltlsys == NULL )
{
puts ("Cannot open file!");
exit(1);
}
}
datsize = sizeof(customer_rec); /*assigning the size of the entire file
that holds customer_rec to datsize*/
while(1) /*infinite loop */
{
clrscr();
menu();
switch(choice)
{
case 1:
fseek(ltlsys,0,SEEK_END); /*causes the pointer to be set in the disk file to the end to write a new record*/
again1='Y';
while(again1=='Y'||again1=='y')
{
gotoxy(5,2);
printf("^^^^^ADD NEW LIBRARY USER^^^^^\n");
printf("\n");
clreol();
do /*x,t,f are used as array indexes in the program*/
{ /*they will be used to access different array members*/
chk=1;
gotoxy(5,6);
clreol();
printf("Please, enter first name:");
gets(customer_rec.f_name[x]);
if(strlen(customer_rec.f_name[x])>9)
{
gotoxy(23,20);
printf("User name must not be greater than 9 characters\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
/* else if(!isalpha(strlen(customer_rec.f_name[x])))
{
gotoxy(23,20);
printf("User name can only have letters\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}*/
else if(strlen(customer_rec.f_name[x]) == 0)
{
gotoxy(23,20);
printf("User name can not be left blank");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
for(f=x;f<x+1;f++) /*The work of the for loop here is to check if
a digit is entered instead of an alphabet*/
{
for(t=0;t<9;t++)
{
if(isdigit(customer_rec.f_name[f][t]))
{
gotoxy(23,20);
printf("Name can only contain alphabets!");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}
}
}while(chk==0);
do
{
chk=1;
gotoxy(5,8);
clreol();
printf("Enter last name:");
gets(customer_rec.l_name[x]);
if(strlen(customer_rec.l_name[x])>9)
{
gotoxy(23,20);
printf("User name must not be greater than 9 characters\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
else if(strlen(customer_rec.l_name[x]) == 0)
{
gotoxy(23,20);
printf("User name can not be left blank");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
for(f=x;f<x+1;f++)
{
for(t=0;t<9;t++)
{
if(isdigit(customer_rec.l_name[f][t]))
{
gotoxy(23,20);
printf("Name can only contain alphabets!");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}
}
}while(chk==0);
do
{
chk=1;
gotoxy(5,10);
printf("Enter user's age:");
gets(customer_rec.age[x]);
fflush(stdin);
if (strlen(customer_rec.age[x]) == 0)
{
gotoxy(20,23);
printf("User's age must not be left unfilled");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.age[x])!=2)
{
gotoxy(20,23);
printf("User's age must be 2 characters long");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(strcmp(customer_rec.age[x],"00")==0)
{
gotoxy(20,23);
printf("User's age cannot be below 1 year");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
for(f=x;f<x+1;f++) /*checks to see if somehting other than a digit is entered*/
{
for(t=0;t<2;t++)
{
if(!isdigit(customer_rec.age[f][t]))
{
gotoxy(20,23);
printf("Enter a valid age!");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
}
}
}while (chk==0);
do
{
chk=1;
gotoxy(5,12);
clreol();
printf("Enter user's gender[M/F]:");
gets(customer_rec.gender[x]);
if(strlen(customer_rec.gender[x])==0)
{
gotoxy(23,20);
printf("User gender can not be left blank.\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
else if(strlen(customer_rec.gender[x])>1)
{
gotoxy(23,20);
printf("Enter M for male or F for female");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}while(chk==0);
do
{
chk=1;
gotoxy(5,14);
clreol();
printf("Date of joining [dd mm yr]");
printf(" separated by a space: ");
scanf("%s %s %s",customer_rec.dd[x], customer_rec.mth[x], customer_rec.yr[x]);
d = atof(customer_rec.dd[x]); /*statement to convert the string in dd to its int eqivalent*/
m = atof(customer_rec.mth[x]); /*statement to convert the string in mth to its int eqivalent*/
y = atof(customer_rec.yr[x]); /*statement to convert the string in yr to its int eqivalent */
if (strlen(customer_rec.dd[x]) == 0)
{
gotoxy(20,23);
printf("Day field must not be left unfilled");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.dd[x])!=2)
{
gotoxy(20,23);
printf("Day field must be 2 characters long");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(strcmp(customer_rec.dd[x],"00")==0)
{
gotoxy(20,23);
printf("Day cannot be below 1");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(d>31)
{
gotoxy(20,23);
printf("Day value cannot be greater than 31");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.mth[x]) == 0)
{
gotoxy(20,23);
printf("Month field must not be left unfilled");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.mth[x])!=2)
{
gotoxy(20,23);
printf("Month field must be 2 characters long");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(strcmp(customer_rec.mth[x],"00")==0)
{
gotoxy(20,23);
printf("Month field cannot be below 1");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(m>12)
{
gotoxy(20,23);
printf("Month value cannot greater than 12");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.yr[x]) == 0)
{
gotoxy(20,23);
printf("Year field must not be left unfilled");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.yr[x])!=4)
{
gotoxy(20,23);
printf("Year field must be 4 characters long");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(y<1900)
{
gotoxy(20,23);
printf("Year cannot be below 1900 ");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
}while(chk==0);
do
{
chk=1;
fflush(stdin);
gotoxy(5,16);
clreol();
printf("Enter ID No:");
gets(customer_rec.id[x]);
/*rewind(ltlsys);
fread(&customer_rec,datsize,1,ltlsys);
{
if(strcmp(customer_rec.id[x],ID)==0)
{
gotoxy(23,20);
printf("User id already assigned!\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}*/
if(strlen(customer_rec.id[x])== 0)
{
gotoxy(23,20);
printf("User must be assigned a valid ID!\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
else if(strcmp(customer_rec.id[x] ,"0000") == 0)
{
gotoxy(23,20);
printf("User ID is invalid!");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
for(f=x;f<x+1;f++)
{
for(t=0;t<4;t++)
{
if(!isdigit(customer_rec.id[f][t]))
{
gotoxy(23,20);
printf("User ID can only contain digits!");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}
}
}while(chk==0);
do
{
chk=1;
gotoxy(5,18);
printf("Enter Address:");
gets(customer_rec.address[x]);
if(strlen(customer_rec.address[x])>40)
{
gotoxy(23,20);
printf("User address must not be greater than 40 characters\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
else if(strlen(customer_rec.address[x]) == 0)
{
gotoxy(23,20);
printf("User address can not be unfilled");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}while(chk==0);
do
{
ser1=strchr(customer_rec.email[x], ser); /*Statement to search for the character '@' from the entered string */
ser2=strchr(customer_rec.email[x], ser0); /*statement to search for the character '.' from the entered string*/
chk=1;
gotoxy(5,20);
clreol();
printf("Enter e-mail address in small letters:");
gets(customer_rec.email[x]);
if(strlen(customer_rec.email[x])>15)
{
gotoxy(23,32);
printf("User e-mail must not be greater than 15 characters\n");
chk=0;
getch();
gotoxy(23,32);
clreol();
}
else if(strlen(customer_rec.email[x]) == 0)
{
gotoxy(23,32);
printf("User e-mail can not be left blank");
chk=0;
getch();
gotoxy(23,32);
clreol();
}
else if(ser1==NULL&&ser2==NULL)
{
gotoxy(23,32);
printf("Enter a valid e-mail address!");
chk=0;
getch();
gotoxy(23,32);
clreol();
}
}while(chk==0);
do
{
chk=1;
gotoxy(5,22);
printf("Enter telephone number:");
gets(customer_rec.tel_num[x]);
if(strlen(customer_rec.tel_num[x])>10)
{
gotoxy(23,32);
printf("Telephone number must not be greater than 10 characters\n");
chk=0;
getch();
gotoxy(23,32);
clreol();
}
else if(strlen(customer_rec.tel_num[x]) == 0)
{
gotoxy(23,32);
printf("User telephone number can not be left blank");
chk=0;
getch();
gotoxy(23,32);
clreol();
}
for(f=x;f<x+1;f++)
{
for(t=0;t<10;t++)
{
if(!isdigit(customer_rec.tel_num[f][t]))
{
gotoxy(23,32);
printf("You entered an invalid value!");
chk=0;
getch();
gotoxy(23,32);
clreol();
}
}
}
}while(chk==0);
gotoxy(24,32);
clreol();
printf("SAVE RECORD[Y/N]? ");
scanf("%c",&save_rec);
getchar();
//fflush(stdin);
if(save_rec=='y'||save_rec=='Y')
{
fwrite (&customer_rec,datsize, 1,ltlsys );
}
else
{
clrscr();
menu();
}
clrscr();
gotoxy(20,28);
printf("\n\n\tWould you like to add another record[Y/N]:?");
scanf("%c",&again1);
getchar();
clrscr();
}
if(again1=='n'||again1=='N')
clrscr();
menu();
break;
case 2:
rewind(ltlsys);
do
{
fread(&customer_rec,datsize,1,ltlsys);
if(!feof(ltlsys))
{
gotoxy(1,1);
printf("////////////////////////////////////////");
printf("////////////////////////////////////////");
printf("///////////////////////// LENNSVILLE LIBRARY");
printf(" DATABASE //////////////////////////");
printf("////////////////////////////////////////");
printf("////////////////////////////////////////\n");
printf("========================================");
printf("========================================\n");
gotoxy(1,6);
printf("FIRST NAME");
gotoxy(12,6);
printf("LAST NAME");
gotoxy(23,6);
printf("ID ");
gotoxy(28,6);
printf("SEX ");
gotoxy(32,6);
printf("AGE");
gotoxy(36,6);
printf("DOJ");
gotoxy(47,6);
printf("ADDRESS");
gotoxy(57,6);
printf("E-MAIL");
gotoxy(68,6);
printf("TELEPHONE");
printf("\n========================================");
printf("========================================");
if(trk==10)
{
gotoxy(80,20);
printf("\n========================================");
printf("========================================");
gotoxy(28,23);
printf("Please Enter To Continue");
getch();
trk=0;
clrscr();
}
gotoxy(1,9+trk);
printf("%s",customer_rec.f_name);
gotoxy(12,9+trk);
printf("%s",customer_rec.l_name);
gotoxy(23,9+trk);
printf("%s",customer_rec.id);
gotoxy(28,9+trk);
printf("%s",customer_rec.gender);
gotoxy(32,9+trk);
printf("%s",customer_rec.age);
gotoxy(36,9+trk);
printf("%s %s %s",customer_rec.dd,customer_rec.mth,customer_rec.yr);
gotoxy(47,9+trk);
printf("%s",customer_rec.address);
gotoxy(62,9+trk);
printf("%s",customer_rec.email);
gotoxy(72,9+trk);
printf("%s",customer_rec.tel_num);
trk++;
}
}while(!feof(ltlsys));
fclose(ltlsys);
gotoxy(30,25+trk);
printf("To return to the main menu, press enter..");
getch();
clrscr();
menu();
break;
case 3:
again1='Y';
while(again1=='Y'||again1=='y')
{
gotoxy(30,8);
printf("^^^^^^^^^^SEARCH MEMBER DATABASE^^^^^^^^^\n");
printf("\n");
printf("\t\tEnter first name to search member details: ");
fflush(stdin);
scanf("%s",fname2);
rewind(ltlsys);
while (fread(&customer_rec,datsize,1,ltlsys)==1)
{
if (strcmp(customer_rec.f_name,fname2)==0)
{
clrscr();
gotoxy(12,1);
printf("SEARCH RESULTS");
gotoxy(12,2);
printf("==============");
gotoxy(12,3);
printf("First name :");
gotoxy(12,5);
printf("Last name :");
gotoxy(12,7);
printf("ID :");
gotoxy(12,9);
printf("Gender :");
gotoxy(12,11);
printf("Age :");
gotoxy(12,13);
printf("D O J :");
gotoxy(12,15);
printf("Address :");
gotoxy(12,17);
printf("E-mail :");
gotoxy(12,19);
printf("Tel No. :");
gotoxy(42,3);
printf("%s",customer_rec.f_name);
gotoxy(42,5);
printf("%s",customer_rec.l_name);
gotoxy(42,7);
printf("%s",customer_rec.id);
gotoxy(42,9);
printf("%s",customer_rec.gender);
gotoxy(42,11);
printf("%s",customer_rec.age);
gotoxy(42,13);
printf("%s %s %s",customer_rec.dd,customer_rec.mth,customer_rec.yr);
gotoxy(42,15);
printf("%s",customer_rec.address);
gotoxy(42,17);
printf("%s",customer_rec.email);
gotoxy(42,19);
printf("%s",customer_rec.tel_num);
}
}
gotoxy(30,28);
printf("Do you want to search for another record[y/n]?:");
fflush(stdin);
scanf("%c",&again1);
clrscr();
}
if(again1=='N'||again1=='n')
fclose(ltlsys);
clrscr();
menu();
break;
case 4:
again1='Y';
while (again1=='y'||again1=='Y')
{
gotoxy(24,4);
printf("^^^^^^^^^MODIFY LIBRARY RECORDS^^^^^^^^^^^");
printf("\n");
printf("Enter member first name to modify:");
fflush(stdin);
scanf("%s",fname2);
rewind(ltlsys);
while(fread(&customer_rec,datsize,1,ltlsys)==1)
{
if(strcmp(customer_rec.f_name,fname2)==0)
{
clrscr();
gotoxy(35,4);
printf(" MEMBER DETAILS");
gotoxy(36,5);
printf("==============");
gotoxy(5,7);
printf("First name :");
gotoxy(5,9);
printf("Last name :");
gotoxy(5,11);
printf("ID :");
gotoxy(5,13);
printf("Gender :");
gotoxy(5,15);
printf("Age :");
gotoxy(5,17);
printf("D O J :");
gotoxy(5,19);
printf("Address :");
gotoxy(5,21);
printf("E-mail :");
gotoxy(5,23);
printf("Tel No. :");
gotoxy(17,7);
printf("%s",customer_rec.f_name);
gotoxy(17,9);
printf("%s",customer_rec.l_name);
gotoxy(17,11);
printf("%s",customer_rec.id);
gotoxy(17,13);
printf("%s",customer_rec.gender);
gotoxy(17,15);
printf("%s",customer_rec.age);
gotoxy(17,17);
printf("%s %s %s",customer_rec.dd,customer_rec.mth,customer_rec.yr);
gotoxy(17,19);
printf("%s",customer_rec.address);
gotoxy(17,21);
printf("%s",customer_rec.email);
gotoxy(17,23);
printf("%s",customer_rec.tel_num);
gotoxy(37,31);
printf("1.Modify first name: ");
gotoxy(37,33);
printf("2.Modify last name :");
gotoxy(37,35);
printf("3.Modify ID :");
gotoxy(37,37);
printf("4.Modify gender :");
gotoxy(37,39);
printf("5.Modify Age :");
gotoxy(37,41);
printf("6.Modify D O J :");
gotoxy(37,43);
printf("7.Modify Address :");
gotoxy(37,45);
printf("8.Modify E-mail :");
gotoxy(37,47);
printf("9.Modify Tel No. :");
gotoxy(37,49);
printf("10.Quit without modification!");
gotoxy(30,53);
printf("Select item below to modify: ");
scanf("%i",&choice2);
getchar();
switch(choice2)
{
case 1:
fname();
break;
case 2:
lname();
break;
case 3:
id();
break;
case 4:
gender();
break;
case 5:
age();
break;
case 6:
doj();
break;
case 7:
address();
break;
case 8:
email();
break;
case 9:
tel_no();
break;
case 10:
menu();
break;
default :
{
gotoxy(30,8);
printf("Invalid choice, made please try again!");
getch();
clrscr();
}
break;
}
fseek(ltlsys,-datsize,SEEK_CUR);
fwrite(&customer_rec,datsize,1,ltlsys);
fclose(ltlsys);
gotoxy(30,8);
printf("\nDetails successfully modified.");
}
}
printf("Would you like to modify another record?[Y/N]\n");
again1=getche();
clrscr();
if(again1=='N'||again1=='n')
clrscr();
menu();
}
break;
case 5:
again1='Y';
while(again1=='Y'|| again1=='y')
{
printf("Enter the first name of the member to be deleted: ");
scanf("%s",fname2);
tempdb=fopen("TEMP.DAT","wb");
rewind(ltlsys);
while(fread(&customer_rec,datsize,1,ltlsys)==1)
{
if(strcmp(customer_rec.f_name,fname2)!=0)
{
fwrite(&customer_rec,datsize,1,tempdb);
}
}
fclose(ltlsys);
fclose(tempdb);
remove("LIBUSER.DAT");
rename("TEMP.DAT","LIBUSER.DAT");
ltlsys=fopen("LIBUSER.DAT","rb+");
printf("Delete another Record(Y/N): ");
fflush(stdin);
again1=getchar();
}
break;
case 6:
{
gotoxy(30,8);
printf("Thank you for today!");
printf("\n\t\t\tClosing database");
for(d=1;d<10;d++)
{
printf(".");
}
fclose(ltlsys);
exit(0);
}
break;
default:
{
gotoxy(30,8);
printf("You made an invalid request!");
printf("\n\t\t\t\tPlease try again");
getch();
clrscr();
menu();
}
break;
}
}
}
}
}
void menu(void) /*menu function*/
{
gotoxy(40,2);
printf("\n\t\t\t @@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
printf("\n\t\t^^^^ LENNSVILLE LIBRARY DATABASE SYSTEM ^^^^" );
printf("\n\t\t\t MAIN MENU ");
printf("\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
printf("\n\t\t\t1.Add library user records\n");
printf("\n\t\t\t2.View library records\n");
printf("\n\t\t\t3.Search library database\n");
printf("\n\t\t\t4.Modify user records\n");
printf("\n\t\t\t5.Delete library user details\n");
printf("\n\t\t\t6.Exit system!");
printf("\n");
printf("\n\t\t\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
printf("\n\t\t\t Select Your Choice [1 - 6]: ");
scanf("%i",&choice);
getchar();
clrscr();
}
void fname(void) /*function for modifying first name of a member*/
{
do
{
chk=1;
gotoxy(5,6);
printf("Enter new first name:");
gets(customer_rec.f_name[x]);
if(strlen(customer_rec.f_name[x])>12)
{
gotoxy(23,20);
printf("New name must be less than 12 characters\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
else if(strlen(customer_rec.f_name[x]) == 0)
{
gotoxy(23,20);
printf("New name can not be left blank");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
for(f=x;f<x+1;f++)
{
for(t=0;t<12;t++)
{
if(isdigit(customer_rec.f_name[f][t]))
{
gotoxy(23,20);
printf("New first name can only have alphabets!");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}
}
}while(chk==0);
}
void lname(void) /*function for modifying a member's last name*/
{
do
{
chk=1;
gotoxy(5,8);
clreol();
printf("Enter new last name:");
gets(customer_rec.l_name[x]);
if(strlen(customer_rec.l_name[x])>12)
{
gotoxy(23,20);
printf("New last name must be less than 12 characters\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
else if(strlen(customer_rec.l_name[x]) == 0)
{
gotoxy(23,20);
printf("New last name must be filled");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
for(f=x;f<x+1;f++)
{
for(t=0;t<12;t++)
{
if(isdigit(customer_rec.l_name[f][t]))
{
gotoxy(23,20);
printf("New name can only contain alphabets!");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}
}
}while(chk==0);
}
void id(void) /*function for modifying a member's ID*/
{
do
{
chk=1;
gotoxy(5,16);
printf("Enter new ID No:");
gets(customer_rec.id[x]);
if(strlen(customer_rec.id[x])== 0)
{
gotoxy(23,20);
printf("New ID must be filled!\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
else if(strcmp(customer_rec.id[x] ,"0000") == 0)
{
gotoxy(23,20);
printf("New ID value is invalid!");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
for(f=x;f<x+1;f++)
{
for(t=0;t<4;t++)
{
if(!isdigit(customer_rec.id[f][t]))
{
gotoxy(23,20);
printf("New ID can only contain digits!");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}
}
}while(chk==0);
}
void gender(void) /*function for modifying gender of a member*/
{
do
{
chk=1;
gotoxy(5,12);
clreol();
printf("Enter new gender[M/F]:");
gets(customer_rec.gender[x]);
if(strlen(customer_rec.gender[x])==0)
{
gotoxy(23,20);
printf("New gender must be filled.\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
else if(strlen(customer_rec.gender[x])>1)
{
gotoxy(23,20);
printf("Enter M for male or F for female");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}while(chk==0);
}
void age(void) /*function for modifying a member's age*/
{
do
{
chk=1;
gotoxy(5,10);
printf("Enter new age:");
gets(customer_rec.age[x]);
fflush(stdin);
if (strlen(customer_rec.age[x]) == 0)
{
gotoxy(20,23);
printf("New age can not be left blank");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.age[x])!=2)
{
gotoxy(20,23);
printf("New age must have 2 characters");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(strcmp(customer_rec.age[x],"00")==0)
{
gotoxy(20,23);
printf("New age value cannot be below 1 year");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
for(f=x;f<x+1;f++)
{
for(t=0;t<2;t++)
{
if(!isdigit(customer_rec.age[f][t]))
{
gotoxy(20,23);
printf("New valid age value required!");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
}
}
}while (chk==0);
}
void doj(void) /*function for modifying a member's date of joining*/
{
do
{
chk=1;
gotoxy(5,14);
clreol();
printf("Date of joining [dd mm yr]");
printf(" separated by a space: ");
scanf("%s %s %s",customer_rec.dd[x], customer_rec.mth[x], customer_rec.yr[x]);
fflush(stdin);
d = atof(customer_rec.dd[x]);
m = atof(customer_rec.mth[x]);
y = atof(customer_rec.yr[x]);
if (strlen(customer_rec.dd[x]) == 0)
{
gotoxy(20,23);
printf("New Day field must be filled");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.dd[x])!=2)
{
gotoxy(20,23);
printf("New Day field must have 2 characters");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(strcmp(customer_rec.dd[x],"00")==0)
{
gotoxy(20,23);
printf("New Day value cannot be below 1");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(d>31)
{
gotoxy(20,23);
printf("New Day value cannot be above 31");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.mth[x]) == 0)
{
gotoxy(20,23);
printf("New month field must be filled");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.mth[x])!=2)
{
gotoxy(20,23);
printf("New month field must have 2 characters!");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(strcmp(customer_rec.mth[x],"00")==0)
{
gotoxy(20,23);
printf("New month field cannot be below 1");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(m>12)
{
gotoxy(20,23);
printf("New month value should be less than 12");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.yr[x]) == 0)
{
gotoxy(20,23);
printf("New Year field must be filled");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if (strlen(customer_rec.yr[x])!=4)
{
gotoxy(20,23);
printf("New Year field must be 4 characters!");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
else if(y<1900)
{
gotoxy(20,23);
printf("New year cannot be below 1900 ");
chk=0;
getch();
gotoxy(20,23);
clreol();
}
}while(chk==0);
}
void address(void) /*function for modifying the address of a member*/
{
do
{
chk=1;
gotoxy(5,18);
printf("Enter new Address:");
gets(customer_rec.address[x]);
if(strlen(customer_rec.address[x])>40)
{
gotoxy(23,20);
printf("New address must be less than 40 characters\n");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
else if(strlen(customer_rec.address[x]) == 0)
{
gotoxy(23,20);
printf("New address can not be blank");
chk=0;
getch();
gotoxy(23,20);
clreol();
}
}while(chk==0);
}
void email(void) /*function for modifying the e-mail of a member*/
{
do
{
ser1=strchr(customer_rec.email[x], '@');
ser2=strchr(customer_rec.email[x], '.');
chk=1;
gotoxy(5,20);
clreol();
printf("Enter new e-mail address in small letters:");
gets(customer_rec.email[x]);
if(strlen(customer_rec.email[x])>15)
{
gotoxy(23,24);
printf("New e-mail must be less than 15 characters\n");
chk=0;
getch();
gotoxy(23,24);
clreol();
}
else if(strlen(customer_rec.email[x]) == 0)
{
gotoxy(23,24);
printf("New e-mail can not be left blank");
chk=0;
getch();
gotoxy(23,24);
clreol();
}
else if(ser1==NULL&&ser2==NULL)
{
gotoxy(23,24);
printf("Enter a new valid e-mail address!");
chk=0;
getch();
gotoxy(23,24);
clreol();
}
}while(chk==0);
}
void tel_no(void) /*function for modifying a member's telephone number*/
{
do
{
chk=1;
gotoxy(5,22);
printf("Enter new telephone number:");
gets(customer_rec.tel_num[x]);
if(strlen(customer_rec.tel_num[x])>10)
{
gotoxy(23,24);
printf("New telephone number must be less than 10 characters\n");
chk=0;
getch();
gotoxy(23,24);
clreol();
}
else if(strlen(customer_rec.tel_num[x]) == 0)
{
gotoxy(23,24);
printf("New telephone number can not be left blank");
chk=0;
getch();
gotoxy(23,24);
clreol();
}
for(f=x;f<x+1;f++)
{
for(t=0;t<10;t++)
{
if(!isdigit(customer_rec.tel_num[f][t]))
{
gotoxy(23,24);
printf("New telephone number can only contain digits!");
chk=0;
getch();
gotoxy(23,24);
clreol();
}
}
}
}while(chk==0);
}