HOW DOI I CALL THIS USING THE FUNCTION AFTER THIS getchar(); printf("Enter name : "); // Here we are using '^' to be able to use a space in the input - > scanf("%[^\ns]",p->name_1920213); printf("Enter last name : "); scanf("%s",p->lastname_1920213); printf("Enter mobile number : "); scanf("%ld",&p->contactnum_1920213); printf("Enter email : "); scanf("%s",p->email_1920213); void search_person() /* this function allows the user to search a specific contacts using the input name, last name, conatact number or email*/ { int choice_1920213; printf("\nChoose one option search for the contact details: \n\n1.First Name \t\t2.Last Name \n3.Mobile Number \t4.Email address \n "); scanf("%d",&choice_1920213); while(1) { switch(choice_1920213) /*Switch statement tests the value of a variable and compares it with multiple cases. Once the case match is found, a block of statements associated with that particular case is executed as given in this program. */ { case 1: // THIS CASE IS FOR SEACHING CONTACT DETAILS USING FIRST NAME // //INPUT LAST NAME WILL RESULT TO PRINTING ALL CONTACT DETAILS OF THE EPRSON { struct p; char fname_1920213[30]; printf("\n\nEnter the first name of the person you want to search : "); scanf ("%s", fname_1920213); FILE *fp; fp = fopen("phonebook_1920213", "rb"); if (fp == NULL) { printf("Error occured while opening the file!\n");
HOW DOI I CALL THIS USING THE FUNCTION AFTER THIS
getchar();
printf("Enter name : ");
// Here we are using '^' to be able to use a space in the input - >
scanf("%[^\ns]",p->name_1920213);
printf("Enter last name : ");
scanf("%s",p->lastname_1920213);
printf("Enter mobile number : ");
scanf("%ld",&p->contactnum_1920213);
printf("Enter email : ");
scanf("%s",p->email_1920213);
void search_person()
/* this function allows the user to search a specific contacts
using the input name, last name, conatact number or email*/
{
int choice_1920213;
printf("\nChoose one option search for the contact details: \n\n1.First Name \t\t2.Last Name \n3.Mobile Number \t4.Email address \n ");
scanf("%d",&choice_1920213);
while(1)
{
switch(choice_1920213)
/*Switch statement tests the value of a variable and compares it with multiple cases.
Once the case match is found, a block of statements associated with that particular case is executed
as given in this
{
case 1: // THIS CASE IS FOR SEACHING CONTACT DETAILS USING FIRST NAME
// //INPUT LAST NAME WILL RESULT TO PRINTING ALL CONTACT DETAILS OF THE EPRSON
{
struct p;
char fname_1920213[30];
printf("\n\nEnter the first name of the person you want to search : ");
scanf ("%s", fname_1920213);
FILE *fp;
fp = fopen("phonebook_1920213", "rb");
if (fp == NULL)
{
printf("Error occured while opening the file!\n");
return;
}
else
{
long int contactnum_1920213 = 0;
phonebook_1920213 p;
while (fread(&p, sizeof(p), 1, fp) == 1)
{
if(strcmp(p.name_1920213, fname_1920213)==0)
{
//PRINTING ALL THE CONTACT DETAILS OF THE SEARCHED PERSON
printf("FIRST NAME: ");
printf("%s",p.name_1920213);
printf("\nLAST NAME: ");
printf("%s",p.lastname_1920213);
printf("\nCONTACT NUMBER: ");
printf("%ld",p.contactnum_1920213);
printf("\nEMAIL ADDRESS: ");
printf("%s",p.email_1920213);
printf("\n");
printf("\nKINDLY PRESS ANY KEY TO CONTINUE USING THE PROGRAM!\n");
contactnum_1920213 = 1;
return;
}
else continue;
}
if(contactnum_1920213 == 0)
{
printf("\nNo Results! The Person you have entered is not in the Phonebook\n");
}
fflush(stdin);
fclose(fp);
printf("\nKINDLY PRESS ANY KEY TO CONTINUE USING THE PROGRAM!\n");
return;
}
}
getchar();
break;
Step by step
Solved in 2 steps