【发布时间】:2015-12-23 13:34:48
【问题描述】:
我必须为使用列表的电话簿开发一个库函数。 此函数必须从列表中删除第 n 个条目。 它是一个链表,条目是结构体,包含字符串名称、srnm、nmbr、addr、int 编号和下一个指针。 但是,每次我调用该函数时,VS 都会给我很多异常和触发断点,并说我损坏了堆。 我不知道我可能在哪里犯了这个损坏堆的错误。请帮助。
这是我到目前为止所做的:
typedef struct list {
char name[20];
char srnm[20];
char nmbr[20];
char addr[20];
unsigned int number;/*Contact index*/
struct list *next;
} entry;
static unsigned int count = 0;
static entry *hol = NULL;/*pointer to the head of the list*/
int delete_contact(unsigned int n) {
int i=0,k=0;
if(n>count) return -1;
hol[n-1].next = hol[n-1].next->next;
for(i=n;i<count;i++) {
hol[i]=hol[i+1];
}
for(i=n;i<count;i++)
hol[i].number = hol[i].number-1; /*Updates the contact index*/
count--; /*Updates the global variable that gives the number of contacts */
return 0;
}
【问题讨论】:
-
您是否真的弄乱了代码中倒数第二条评论 (
+/) 还是仅针对这个问题添加了该评论? -
只针对这个问题,我写的时候没有找错误。
标签: list function heap-memory ansi-c