Below is the code of an example of structure. When I add multiple information for different person all the time it shows output same the last inserted information. How can I fix it?
#include<stdio.h>
#include<string.h>
struct Person{
char *name;
char *adress;
}p[100];
void insert(int ind , char *name, char *adress){
p[ind].name = name;
p[ind].adress = adress;
}
void display(int n){`enter code here`
for(int i =0 ; i<n ; ++i){
printf("%s %s\n" , p[i].name , p[i].adress);
}
}
int main(){
char name[100] , address[100];
for(int i = 0 ; i<2 ; ++i){
fflush(stdin);
gets(name);
fflush(stdin);
gets(address);
insert(i , name , address);
}
display(2);
return 0;
}