https://www.bybit.com/register?affiliate_id=38000&group_id=52135&group_type=1
[856x508] Get $90 Rewards

C Programming code for Searching Name & Updating Address Data structures (Pointers*)

Write a Modular C Programming code for Searching Name & Updating Address Data structures (Pointers*)

Read the number of students, read their information, and display the details of the students:

CODE:

#include<stdio.h>
struct person
{
char name[30];
char address[100]
};
struct person b[1000];
struct person *p;
void readStructure(struct person *p ,int n);
void displayStructure(struct person *p ,int n);

void searchperson(struct person *p , int n);
void update(struct person *p , int n);

main()
{
    p=&b;
int n;
int k;
printf("Enter the number of Persons: ");
scanf("%d",&n);
readStructure(b,n);

searchperson(b,n);



}
void readStructure(struct person *p ,int n)
{
int i;
for(i=0;i<n;i++) { printf("\nEnter Details of Person %d",i+1); printf("\nEnter the Name:"); scanf("%s",&(p+i)->name);
printf("Enter the Address: ");
scanf("%s",&(p+i)->address);
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
}
void displayStructure(struct person *p ,int n)
{

printf("\nDetails of person\n");
printf("\nName: %s",(p+n)->name);
printf("\nAddress: %s",(p+n)->address);
printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");

}

void searchperson(struct person *p , int n)
{
int i,j,x;
char k[30];
int flag=1;
printf("\nEnter the persons Name to search:");
scanf("%s",&k);
    for(i=0;i<n;i++) 
{ 
if((strcmp(k,(p+i)->name)) == 0)
            {
            printf("\nPerson found!!!\n");
            printf("\nName= %s\nAddress= %s\n",(p+i)->name,(p+i)->address);
            flag=1;
            x=i;
            update(b,x);
            break;

            }
        else
        flag=0;
    }
if(flag==0)
{
printf("\nPerson not found!!!");
printf("\n-----------------------------------------------------------------------------------------------------------\n");
}


}

void update(struct person *p , int n)
{
    printf("Enter Updated address: ");
    scanf("%s",&(p+n)->address);
    printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");
    printf("\nUpdated address: ");
    displayStructure(b,n);
}

OUTPUT

Enter the number of Persons: 3

Enter Details of Person 1
Enter the Name:Rocky
Enter the Address: Mumbai

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter Details of Person 2
Enter the Name:Adheera
Enter the Address: SouthIndia

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter Details of Person 3
Enter the Name:Inayath
Enter the Address: Dubai

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter the persons Name to search:Rocky

Person found!!!

Name= Rocky
Address= Mumbai
Enter Updated address: KGF
+++++++++++++++++++++++++++++++++++++++++++++++++
Updated address:
Details of person

Name: Rocky
Address: KGF
+++++++++++++++++++++++++++++++++++++++++++++++++

Process returned 0 (0x0)   execution time : 206.041 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 

Leave a Comment