运行时please input the name:,然后直接是are you sure? y/n,中间没有。请各位帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/29 16:22:56
void Delete()
{ printf("\n\n\tplease input the name:\n");
gets(name1); p4=head;
if(strcmp(p4->name,name1)!=0&&p4!=NULL)
{ p4=p4->next;
}
if(strcmp(p4->name,name1)!=0&&p4==NULL)
printf("it's not exit in the addr-book!");
else
{ while(!strcmp(p4->next->name,name1)==0)
{ printf("are you sure? y/n");
scanf("%c",&x);
if(strcmp(x,"y")==0)
{
if(p4==head)
{
head=head->next;
free(p5);
}
else
{
p4->next=p5->next;
free(p5);
}
}
else
return;
}

}
}
p4,p5为全局变量。此部分功能是删除通讯录的信息。输入姓名后如果没有,则说明无此人,存在则提示确定要删除?得到答案后执行

void
Delete(void)
{
struct node * p4, * p5;

printf("\n\n\tplease input the name:\n");
fflush(stdin);
gets(name1);

p4 = head;
while ( p4 != NULL && strcmp(p4->name, name1)!= 0 ) {
p5 = p4;
p4 = p4->next;
}

if( p4 == NULL )
printf( "it doesn`t exist in the addr-book!" );
else {
printf( "are you sure? y/n" );
scanf( "%c", &x );
fflush(stdin);
if( x == 'y' || x == 'Y') {
if( p4 == head && p4->next != NULL ) {
head = p4->next;
free(p4);
}
else if ( p4->next == NULL )
head = NULL;
else {
p5->next = p4->next;
free(p4);
}
}
}
}

你用的p4和p5是全局变量吧,那你要仔细阅读我改的程序,看懂了之后自己协调一下,因为我没有看到你的代码的上下文。

楼主,你不用跟我解释你这个函数干什么的,我当然知道是干什么的,不然我怎么能给你改