链表问题
为什么会出现有乱码的呢?而且输出也有问题。。求高手解答
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student
{
char name[20];
char sno[13];
int mark;
}student;
typedef struct Node
{
student studentInfo;
struct Node *next;
}LinkList;
LinkList *input()
{
LinkList *s;
s=(LinkList *)malloc(sizeof(LinkList));
s->next=0;
return s;
}
void insert(LinkList *stu,LinkList *stulist)
{
LinkList *pointer = stulist;
LinkList *stupointer =stulist->next;
while(stupointer!=0&& stupointer->studentInfo.mark<=stu->studentInfo.mark)
{
pointer =stupointer;
stupointer=stupointer->next;
}
pointer->next=stu;
stu->next =stupointer;
}
int search(LinkList *L, char sno[13])
{
LinkList *S = L,*P;
while(S && (strcmp(S->studentInfo.sno, sno) != 0))
S = S->next;
if(!S->next)
printf("NO FIND!\n");
else
{
P = S->next;
S->next = P->next;
free(S);
}
return 0;
}
void main()
{
LinkList *stulist,*stu,*stupointer;
stulist=input();
stu=(LinkList *)malloc(sizeof(LinkList));
printf("插入3个学生");
strcpy(stu->studentInfo.sno,"001");
strcpy(stu->studentInfo.name,"张1");
stu->studentInfo.mark=90;
stu->next=0;
insert(stu,stulist);
stu=(LinkList *)malloc(sizeof(LinkList));
strcpy(stu->studentInfo.sno,"002");
strcpy(stu->studentInfo.name,"张2");
stu->studentInfo.mark=85;
stu->next=0;
insert(stu,stulist);
stu=(LinkList *)malloc(sizeof(LinkList));
strcpy(stu->studentInfo.sno,"003");
strcpy(stu->studentInfo.name,"张3");
stu->studentInfo.mark=87;
stu->next=0;
insert(stu,stulist);
stupointer=stulist;
while(stupointer!=0)
{
printf("%s,%s,%d\n",stupointer->studentInfo.sno,stupointer->studentInfo.name
,stupointer->studentInfo.mark);
stupointer=stupointer->next;
}
printf("\n");
printf("删除一个学号为001的学生后:\n");
search(stu,"001");
while(stupointer!=0)
{
printf("%s,%s,%d\n",stupointer->studentInfo.sno,stupointer->studentInfo.name
,stupointer->studentInfo.mark);
stupointer=stupointer->next;
}
}