本人是新手小白,刚入编程的门,有个链表问题请教大神
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#include <conio.h>
void menu();
void choose();
char ch;
char a[100];
char b[30];
struct word *head;
struct word *creat(struct word *head);
struct word *delet(struct word *head,char a[100]);
void print(struct word *head);
struct word
{
char a[100];
struct word *next;
};
void main ()
{
system("color 0b");
menu();
do
{
scanf("%c",&ch);
system("cls");
choose();
}while(ch!='4');
}
void choose()
{
switch(ch)
{
case '1':creat(head);
break;
case '2':print(head);
break;
case '3':delet(head,a);
break;
case '4':printf("\n\n\t感谢您的使用!\n");
break;
getch();
default:menu();
printf("\n\t\t请重新选择:");
}
}
void menu()
{
char *s[5]={"1-输入单词","2-查看单词","3-删除单词","4-退出词汇表","请选择:"};
int i;
printf("\t\t----------英语单词学习系统----------");
printf("\n");
printf("\t++++++++++++++++++++++++++++++++++++++++++++");
printf("\n");
for(i=0;i<5;i++)
{
printf("\t\t----------");
printf("%s",s[i]);
printf("----------");
printf("\n");
}
}
struct word *creat(struct word *head)
{
struct word *p1,*p2;
head=p1=p2=NULL;
while(p1->a>0)
{
p1=(struct word*)malloc(sizeof(struct word));
printf("请输入单词,输入0时结束\n");
scanf("%c",&p1->a);
if(head==NULL)
head=p1;
else
p2->next=p1;
p2=p1;
}
free(p1);
p1=NULL;
p2->next=NULL;
printf("单词本输入结束");
return head;
}
void print(struct word *head)
{
struct word *temp;
temp=head;
printf("单词表为:\n");
while(temp!=NULL)
{
printf("%c\n",*temp->a);
temp=temp->next;
getch();
}
}
struct word *delet(struct word *head,char a)
{
struct word *temp,*p;
temp=head;
if (head==NULL)
printf("\nListis null!\n");
else
{
temp=head;
while (*temp->a!=a&&temp->next!=NULL)
{
p = temp;
temp = temp->next;
}
if(*temp->a==a)
{
if(temp==head)
{
printf("delete string :%d\n",temp->a);
head=head->next;
free(temp);
}
else
{
p->next=temp->next;
printf("delete string :%d\n",temp->a);
free(temp);
}
}
else
printf("\nno find string!\n");
}
return(head);
}
void choose 那对链表的调用有问题吧,但是我不知道怎么改!!!!