free함수 이렇게 쓰는거 아닌가요?ㅜㅜ
아니면 다른데 문제가 있는 건가요?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct a
{
char b[3];
char e[3];
};
void x(struct a **c, int i)
{
fputs("b:", stdout);
scanf("%s", (*c)[i].b);
fputs("c:", stdout);
scanf("%s", (*c)[i].e);
}
void y(struct a **c, int i)
{
printf("b : %s, e : %s\n", (*c)[i].b, (*c)[i].e);
}
void z(struct a **c, int i)
{
char aa[3];
fputs("b :", stdout);
scanf("%s", &aa);
for(int k=0; k<i; k++)
if(strcmp(aa, (*c)[k].b)==0)
{
free(c[k]);
for(int s=0; s<3; s++)
printf("b :%s, e :%s\n", (*c)[s].b, (*c)[s].e);
}
}
int main()
{
int i=0;
struct a *c[6];
c[i]=(struct a*)malloc(sizeof(struct a));
for(i=0; i<3; i++)
x(c,i);
for(int k=0; k<3; k++)
y(c, k);
z(c,3);
for(int s=0; s<3; s++)
free(c[s]);
return 0;
}
자세히는 안 봤지만 반복문에서 건드리고 있는 와중에 그걸 해제하는 건 대단한 주의가 필요