#include<stdio.h>
struct classifier
{
char src_address[15];
char dst_address[15];
int src_port;
int dst_port;
};
void display(struct classifier *ptr)
{
printf("\n%s", ptr->src_address );
printf("\n%s", ptr->dst_address );
printf("\n%d", ptr->src_port);
printf("\n%d", ptr->dst_port );
}
main()
{
int i;
struct classifier *ptr[4];
for(i=0;i<2;i++)
{
scanf("%s",ptr[i]->src_address);
scanf("%s",ptr[i]->dst_address);
scanf("%d",&ptr[i]->src_port);
scanf("%d",&ptr[i]->dst_port);
display(ptr[i]);
}
return 0;
}
I want to display the output in a function. When I enter data for the first time, I get a proper display. When I enter the data a second time, it displays a segmentation error. What is wrong with the code? According to my information, I correctly formulated pointers. Please, help.
source
share