Там два "свободных (т)" на моей функции.Когда я вызываю функцию и перехожу к первому свободному (t), все работает нормально, тогда функция self вызывает себя, а затем, в свободном (t) дне кода, происходит сбой сегментации.Почему это происходит?И почему первый «free (t)» не приводит к ошибке сегментации и результату secund?Спасибо
char c[50];
int b, j=0, d=0, e=0;
PLAYER *pt1;
MANAGER *pt2;
t=malloc(24*sizeof(TEAM));
tfile=fopen("team.txt", "r");
while(fscanf(tfile, "%d %s %d %d %d%c", &t[j].tablep, t[j].initials, &t[j].birth.day, &t[j].birth.month, &t[j].birth.year)!=EOF){
fgets(t[j].name, 50, tfile);
t[j].name[strlen(t[j].name)-1]='\0';
j++;
}
fclose(tfile);
t[j].name[0]=0;
j=0;
while(t[j].name[0]!=0){
printf("\t%i. %s\n", j+1, t[j].name);
j++;
}
do{
printf("What is the team of the player:");
scanf(" %c", &b);
b=b-48;
if(b<1 || b>j+1){
printf("Invalid choice. Try again.\n");
teamlists(a);
}
}while(b<1 || b>j);
j=0;
if(a==2){
}
else{ //(a==3)
pt2=malloc(sizeof(MANAGER));
memcpy(pt2, m, sizeof(*pt2));
m=malloc(24*sizeof(MANAGER));
reader(3);
while(m[j].name[0]!=0){
if(strcmp(m[j].team, t[b-1].name)==0){
do{
printf("This team already have a manager.\nEnter: \t1. to choose another team \t2. to return to menu ");
scanf(" %c", &e);
e=e-48;
if(e!=1 && e!=2)
printf("Invalid choice. Try again.\n");
if(e==1 || e==2){
free(t);
free(m);
}
if(e==1){
m=malloc(sizeof(MANAGER));
memcpy(m, pt2, sizeof(*m));
teamlists(a);
}
if(e==2){
main();
free(pt2);
}
}while(e!=1 && e!=2);
}
j++;
}
free(m);
memcpy(m, pt2, sizeof(*m));
strcpy(m->team, t[b-1].name);
free(t);
free(pt);
}
}