链表的问题,到底哪错了

来源:百度知道 编辑:UC知道 时间:2024/05/10 12:00:43
今天写了一个单链表的建立,查找,删除的小程序
但是当我吧参数设置的很大的时候(大于25的时候)他为什么只可以输入25个数据呢?到25个的时候就结束了显示press anykey to continue
高手帮我看看!:是我程序出错 了
/************************************************************/
#include <stdio.h>
#include <malloc.h>
#include <string.h>
struct stu
{
char name[20];
stu *link;
};
stu *create(int n);
void insert(stu *head);
stu *searched(stu *head,char *ch);
void main()
{
stu *head,*sear;
char ch[20];
head=create(30);
scanf("%s",ch);
sear=searched(head,ch);
printf("%s",sear->name);
insert(sear);
sear=NULL;
scanf("%s",ch);
sear=searched(head,ch);
printf("%s",sear->name);
}
stu *create(int n)
{
stu *head,*van,*nonce;//head用来保存链表表头,*van用来表示当前指针的前一个指针,*nonce用来表示当前指针
head=(stu *)malloc(sizeof(stu *));//初始化head分配内存
if(head==NULL)
{
print

把所有类似的内存分配
head=(stu *)malloc(sizeof(stu *));//初始化head分配内存
改为
head=(stu *)malloc(sizeof(stu));//初始化head分配内存

尝试以下程序

/************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct stu
{
char name[20];
struct stu *link;
};
struct stu *create(int n);
void insert(struct stu *head);
struct stu *searched(struct stu *head,char *ch);
void main()
{
struct stu *head,*sear;
char ch[20];
head=create(30);
scanf("%s",ch);
sear=searched(head,ch);
printf("%s",sear->name);
insert(sear);
sear=NULL;
scanf("%s",ch);
sear=searched(head,ch);
printf("%s",sear->name);
free(head);
}
struct stu *create(int n)
{
int i;
struct stu *head,*van,*nonce;//head用来保存链表表头,*van用来表示当前指针的前一个指针,*nonce用来表示当前指针
hea