关于vs2019 .exe触发一个断点的错误:
可能是在访问动态内存管理的数组是越界;
void Initcontact(struct contact* con)
{
con->arr = (struct peoinfo*)malloc(DEFAULT_SZ * sizeof(struct peoinfo));
if (con->arr == NULL)
{
return ;
}
con->size = 0;//设置通讯录初始元素只有一个
con->capacity = DEFAULT_SZ;
//把文件中存在的信息加载到通讯录中
loadcontact(con);
}
void CheckCapacity(struct contact* ps)
{
if (ps->size== ps->capacity)
{
//增容
struct peoinfo*ptr=(struct peoinfo* )realloc(ps->arr, (2 + ps->capacity) * sizeof(struct peoinfo));
if (ptr != NULL)
{
ps->arr = ptr;
ps->capacity += 2;
printf("增容成功\n");
}
else
{
printf("增容失败\n");
}
void loadcontact(Contact* con)
{
FILE* pf = fopen("contact.txt", "rb");
if (pf == NULL)
{
printf("%s\n", strerror(errno));
return;
}
while (fread(&(con->arr[con->size]), sizeof(struct peoinfo), 1, pf))
{
CheckCa