|
发表于 2013-7-2 14:31:25
|
显示全部楼层
int book_id_test( int id )//这里用bool要加头文件 1表示true 0表示false
{
struct book * p = head;
for ( p = head; p; p = p->next )
{
if ( p->book_id == id )
return 1;
}
return 0;
}
void add_book() //添加图书信息
{
struct book *asd;
asd = (struct book*)malloc(sizeof(struct book));
printf("请输入书籍编号:\n");
scanf("%d",&(asd->book_id));
printf("请输入书籍名称:");
scanf("%s",asd->book_name);
printf("请输入书籍作者名字");
scanf("%s",asd->book_writer);
while ( book_id_test( asd->book_id ) )
{
printf( "输入id以存在请重新输入" );
fflush( stdin );
printf("请输入书籍编号:\n");
scanf("%d",&(asd->book_id));
printf("请输入书籍名称:");
scanf("%s",asd->book_name);
printf("请输入书籍作者名字");
scanf("%s",asd->book_writer);
}
asd->next = NULL;
if(head == NULL)
{
head = asd;
}
else
{
asd->next=head;
head=asd;
}
return;
}
|
|