#include “stdlib.h”
#include “stdio.h”
#define Max 10
struct List
{
int Number;
char Name[Max];
struct List *Next;
};
typedef struct List Node;
typedef Node* Link;
Link Creat_List(Link Head)
{
int DataNum;
char DataName[Max];
Link New;
Link Pointer;
int i;
Head=(Link)malloc(sizeof(Node));
if(Head==NULL)
printf(“Memory allocate Failure!!\n”);
else
{
DataNum=1;
printf(“Please input the data name ; “);
scanf(“%s”,DataName);
Head->Number=DataNum;
for(i=0;i<=Max;i++)
Head->Name[i]=DataName[i];
Head->Next=NULL;
Pointer=Head;
while(1)
{
DataNum++;
New=(Link)malloc(sizeof(Node));
printf(“Please input the data name : “);
scanf(“%s”,DataName);
if(DataName[0]==’0′)
break;
New->Number=DataNum;
for(i=0;i<=Max;i++)
New->Name[i]=DataName[i];
New->Next=NULL;
Pointer->Next=New;
Pointer=New;
}
}
}
void Print_List(Link Head)
{
Link Pointer;
Pointer=Head;
while(Pointer!=NULL)
{
printf(“##Input Data##\n”);
printf(“Data Number : %d\n”,Pointer->Number);
printf(“Data Name : %s\n”,Pointer->Name);
Pointer=Pointer->Next;
}
}
void Free_List(Link Head)
{
Link Pointer;
while(Head!=NULL)
{
Pointer=Head;
Head=Head->Next;
free(Pointer);
}
}
void main()
{
Link Head;
Head=Creat_List(Head);
if(Head!=NULL)
{
Print_List(Head);
Free_List(Head);
}
}
>> 本文固定链接: http://www.vcgood.com/archives/3107
编译时没有提示问题,但执行出故障…
我知道了,是CREAT函数忘记加上返回值了……