#include <stdio.h> #include <malloc.h> #include <stdlib.h> typedef struct test { int date; struct test *pTest; }* PTEST,TEST; PTEST create_head(); void shuchu(struct test *); int main (void) { PTEST p_head; p_head=create_head(); shuchu(p_head); return 0; } PTEST create_head() { int len; int i; int val; PTEST ptail; PTEST P_head=(struct test *)malloc(sizeof(struct test));//对了 他是头 所以用*号类型的 //创建一个头指针不是首指针 if(NULL==P_head){ printf("失败"); exit(-1); } ptail=P_head; printf("几个:"); scanf("%d",&len); for (i=1;i<len+1;i++) { printf("第%d个的值",i); scanf("%d",&val); //创建一个新的值 PTEST pnew=(PTEST)malloc(sizeof(TEST)); if(NULL==pnew) { printf("失败"); exit(-1); } pnew->date=val; ptail->pTest=pnew; pnew->pTest=NULL; ptail=pnew; } return P_head; } void shuchu (PTEST phead) { PTEST p = phead->pTest;//p是指向最后的一个的指针; while (p!=NULL) { printf("%d ,",p->date); p=p->pTest; } printf(" "); }