I don't know how to fix this.
Here's my code. The error's at the last line.
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define max_con 30
void add_contact();
void edit_contact();
void del_contact();
void list_contact();
char addressbook[5][30][30];
char mode;
int address_count = 0, current_record = 0;
int main(void)
{
do
{
printf("Welcome: This is an address book program brought to you by\nJohn Ranniel G. Sison\n");
printf("Select the mode you want\n");
printf("1 -> Add contact\n");
printf("2 -> Edit contact\n");
printf("3 -> Delete contact\n");
printf("4 -> List contact\n");
printf("5 -> Exit the program\n");
scanf("%c", &mode);
switch(mode){ //switch (determine which action to take)
case '1':
add_contact();
break;
case '2':
edit_contact();
break;
case '3':
del_contact();
break;
case '4':
list_contact();
break;
case '5':
return 0;
default:
while(mode<5&&mode>=1)
printf("Please choose from the given options.\n");
scanf("%c", &mode);
}
}
while(mode != '5');
}
void add_contact()
{
char entry[30];
int i, length, flag;
if(mode=='1')
if (address_count == max_con){ //checks if the number of contacts is has not yet reached the maximum which is max_con
printf("Sorry, the %d entry limit has been reached.\nChoose other functions other than '1'", max_con);
return;
}
else {
address_count++; //variable for number of entries
current_record = address_count-1; //variable for the current entry
length = strlen(addressbook[0][current_record]);
//asks the user to input the entry's first name (Alphabet, spaces) and it must not exceed 20 characters
do
{
printf("Enter the first name:"); //asks the user to input the first name of the entry
scanf("%s", addressbook[0][current_record]);
length = strlen(addressbook[0][current_record]); //gets the length of the input (should be less than 20)
for(i=0; i<=20; i++)
{
if(isalpha((addressbook[0][current_record][i])||addressbook[0][current_record][i]==' ')&&length<20)
{ //checks if the input characters in first name are alphabets/a space and strlen is less than 20
flag = 1;
break; //
} //exits once it sees that the characters are alpha numeric
else
{
printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
break;
}
}
}
while(flag!=1);
//asks the user to input the surname of the entry (Alphabet, spaces) and it must not exceed 20 characters
flag = 0;
do
{
printf("Enter the surname:"); //
scanf("%s", addressbook[1][current_record]);
length = strlen(addressbook[1][current_record]); //gets the length of the input (should be less than 20)
for(i=0; i<=20; i++){
if(isalpha((addressbook[1][current_record][i])||addressbook[1][current_record][i]==' ')&&length<20)
{ //checks if the input characters in surname are alphabets/a space and strlen is less than 20
flag = 1;
break; //
} //exits once it sees that the characters are alpha numeric
else
{
printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
break;
}
}
}
while(flag!=1);
//asks the user to input the degree program of the entry(Alphabet, spaces) and it must not exceed 20 characters
flag = 0;
do{
printf("Enter the Degree Program the entry's in:");
scanf("%s", addressbook[2][current_record]);
length = strlen(addressbook[2][current_record]); //gets the length of the input (should be less than 20)
for(i=0; i<=20; i++)
{
if(isalpha((addressbook[2][current_record][i])||addressbook[2][current_record][i]==' ')&&length<20)
{ //checks if the input characters in the degree program are alphabets/a space and strlen is less than 20
flag = 1;
break;
} //exits once it sees that the characters are alpha numeric
else
{
printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
break;
}
}
}
while(flag!=1);
flag = 0;
do
{
printf("Enter the entry's Student ID:");
scanf("%s", addressbook[3][current_record]);
length = strlen(addressbook[3][current_record]); //gets the length of the input (should be 10)
addressbook[3][current_record];
for(i=0; i<10; i++)
{
if((addressbook[3][current_record][i]>='0')&&(addressbook[3][current_record][i]<'4')||(addressbook[3][current_record][i]>'4')&&(addressbook[3][current_record][i]<=9))
//checks if the input characters are only numbers and the 4th element of the array is a '-'
if((addressbook[3][current_record][4]=='-')&&(strlen(addressbook[3][current_record])=='10'))
{ //checks if the input characters are only numbers and the 4th element of the array is a '-'
flag = 1;
break;
}
else
{ //prints restrictions/parameters for the student ID
printf("The format of your input should be like this:\nxxxx-yyyyy\nWhere: the x's and y's represent ONLY numbers");
break;
}
}
}
while(flag!=1);
flag = 0;
do
{
printf("Enter the entry's cellphone number:");
scanf("%s", addressbook[4][current_record]);
length = strlen(addressbook[4][current_record]); //gets the length of the input (should be 10)
//checks if the input is composed of 11 elements wherein the first 2 are 0 and 9 respectively
for(i=0; i<11; i++){
if((addressbook[4][current_record][0] == '0')&&addressbook[4][current_record][1] == '9'||(addressbook[4][current_record][i]>='0')&&(addressbook[4][current_record][i]<='9')&&(length)=='11')
{
flag = 1;
break;
}
else
{ //prints restrictions/parameters for the cellphone number
printf("The format of the input is: 09xxyyyyyyy\nwherein x and y are integers from 0 -> 9\n");
break;
}
}
}
while(flag!=1);
flag = 0;
do
{
printf("Enter the entry's email address:");
scanf("%s", addressbook[5][current_record]);
length = strlen(addressbook[5][current_record]); //gets the length of the input (should be 10)
//checks if input is composed of letters//digits/underscores/dots/@ &max of 30 characters
for(i=0; i<30; i++){
if((addressbook[5][current_record][i]>='A')&&(addressbook[5][current_record][i]<='z')||(addressbook[5][current_record][i]=='.')||
(addressbook[5][current_record][i]=='@')||(addressbook[5][current_record][i]=='_')||(addressbook[5][current_record][i]>='0')&&(addressbook[5][current_record][i]<='9')&&length<=30)
{
flag = 1;
break;
}
else
{ //prints restrictions/parameters for the cellphone number
printf("The email address entry can only be composed of letters, numbers, '.', '_' and '@' \n");
break;
}
}
}
while(flag!=1);
} //end add_contact function
void edit_contact()
{
char i, j, k, flag, length;
int num;
printf("Edit which entry?\n");
printf("------------------\n");
printf("Enter the number of the entry you want to edit:");
scanf("%d", &num);
//edits first name of entry
do
{
printf("Edit the first name:"); //asks the user to input the first name of the entry
scanf("%s", addressbook[0][num]);
length = strlen(addressbook[0][num]); //gets the length of the input (should be less than 20)
for(i=0; i<=20; i++)
{
if(isalpha((addressbook[0][num][i])||addressbook[0][num][i]==' ')&&length<20)
{ //checks if the input characters in first name are alphabets/a space and strlen is less than 20
flag = 1;
break;
} //exits once it sees that the characters are alpha numeric
else
{
printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
break;
} //end else
}
}
while(flag!=1);
//edits surname
//asks the user to input the surname of the entry (Alphabet, spaces) and it must not exceed 20 characters
flag = 0;
do
{
printf("Edit the surname:"); //
scanf("%s", addressbook[1][num]);
length = strlen(addressbook[1][num]); //gets the length of the input (should be less than 20)
for(i=0; i<=20; i++)
{
if(isalpha((addressbook[1][num][i])||addressbook[1][num][i]==' ')&&length<20)
{ //checks if the input characters in surname are alphabets/a space and strlen is less than 20
flag = 1;
break; //
} //exits once it sees that the characters are alpha numeric
else
{
printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
break;
} //end else
} // end for
} //end do
while(flag!=1);
//edits the course
//asks the user to input the degree program of the entry(Alphabet, spaces) and it must not exceed 20 characters
do{
printf("Enter the Degree Program the entry's in:");
scanf("%s", addressbook[2][num]);
length = strlen(addressbook[2][num]); //gets the length of the input (should be less than 20)
for(i=0; i<=20; i++){
if(isalpha((addressbook[2][num][i])||addressbook[2][num][i]==' ')&&length<20)
{ //checks if the input characters in the degree program are alphabets/a space and strlen is less than 20
flag = 1;
break; //
} //exits once it sees that the characters are alpha numeric
else {
printf("You can only use alphabets and space and a maximum of 20 characters. First name?\n"); //puts a message that prompts the user to enter alphabets/space alone
break;} //end else
} // end for
} //end do
while(flag!=1);
// edits student ID of entrynumber
flag = 0;
do{
printf("Edit the entry's Student ID:");
scanf("%s", addressbook[3][num]);
length = strlen(addressbook[3][num]); //gets the length of the input (should be 10)
addressbook[3][current_record];
for(i=0; i<10; i++){
if((addressbook[3][num][i]>='0')&&(addressbook[3][num][i]<'4')||(addressbook[3][num][i]>'4')&&(addressbook[3][num][i]<=9))
//checks if the input characters are only numbers and the 4th element of the array is a '-'
if((addressbook[3][num][4]=='-')&&(strlen(addressbook[3][num])=='10'))
{ //checks if the input characters are only numbers and the 4th element of the array is a '-'
flag = 1;
break;
}
else { //prints restrictions/parameters for the student ID
printf("The format of your input should be like this:\nxxxx-yyyyy\nWhere: the x's and y's represent ONLY numbers");
break; } //end else
} //end for
} // end do
while(flag!=1);
//edit cellphone number
flag = 0;
do
{
printf("Edit the entry's cellphone number:");
scanf("%s", addressbook[4][num]);
length = strlen(addressbook[4][num]); //gets the length of the input (should be 10)
//checks if the input is composed of 11 elements wherein the first 2 are 0 and 9 respectively
for(i=0; i<11; i++){
if ((addressbook[4][num][0] == '0') && (addressbook[4][num][1] == '9') || (addressbook[4][num][i]>='0') && (addressbook[4][num][i]<='9'))
{
if(length == 11){
flag = 1;
break;
}
}
else { //prints restrictions/parameters for the cellphone number
printf("The format of the input is: 09xxyyyyyyy\nwherein x and y are integers from 0 -> 9\n");
break; } //end else
} //end for
} // end do
while(flag!=1);
//edit email address
flag = 0;
do
{
printf("Enter the entry's email address:");
scanf("%s", addressbook[5][num]);
length = strlen(addressbook[5][num]);
//checks if input is composed of letters//digits/underscores/dots/@ &max of 30 characters
for(i=0; i<30; i++){
if((addressbook[5][num][i]>='A')&&(addressbook[5][num][i]<='z')||(addressbook[5][num][i]=='.')||
(addressbook[5][num][i]=='@')||(addressbook[5][num][i]=='_')||(addressbook[5][num][i]>='0')||(addressbook[5][num][i]<='9')&&length<=30){
flag = 1;
break;
}
//prints restrictions/parameters for the cellphone number
else {
printf("The email address entry can only be composed of letters, numbers, '.', '_' and '@' \n");
break; }
}
}
while(flag!=1);
}
void del_contact()
{
int del, i;
printf("Enter the number of entry/contact you want to delete.\n");
printf("Contact number:");
scanf("%d", &del);
//for loop to assign '/0' as the content for the given entry
for(i=0; i<6; i++)
{
strcpy(addressbook[i][del], addressbook[6][0]);
}
//after deletion of the contents of the entries, address_count and current_record are both reset to 0
address_count = 0;
current_record = 0;
} //end delete function