#define _TEST_STRUCT_C
//结构体定义
struct Student
{
//业务数据
const char name[32];
int id;
int classID;
//下面的字段纯粹是为了建立链表用
struct TstField
{
struct Student *sle_next;
} MyField;
LIST_ENTRY(Student) ListField;
};
void* NewStudent();
#endif
#ifndef _TEST_LIST_C
#define _TEST_LIST_C
#include "innerStruct.h"
LIST_HEAD(StudentList,Student);
struct StudentList sutListHead;
void TestList();
static void OutputAll();
#endif
#include <stdio.h>
#include "queue.h"
#include "TestList.h"
void TestList()
{
struct Student *stu;
struct Student *stu1;
struct Student *stu2;
int i;
LIST_INIT(&sutListHead);
stu=NewStudent();
if(NULL==stu){return;}
stu->classID=0;
stu->id=100;
strcpy(stu->name,"jiayp");
LIST_INSERT_HEAD(&sutListHead,stu,ListField);
stu1=LIST_FIRST(&sutListHead);
for(i=0;i<3;i++)
{
stu=NewStudent();
if(NULL==stu){return;}
stu->classID=i;
stu->id=100;
strcpy(stu->name,"sun");
LIST_INSERT_AFTER(stu1,stu,ListField);
}
OutputAll();
}
static void OutputAll()
{
struct Student *stu3;
LIST_FOREACH(stu3,&sutListHead,ListField)
{
printf(stu3->name);
printf("\r\n");
}
}