程序代码:
#include <stdio.h> #include <malloc.h> #include <string.h> typedef struct info { char p[1024]; struct info * next; } Info; Info * test() { int count = 10, i; Info * head, *p; char * s = "hello"; head = p = (Info *) malloc(sizeof(Info)); for (i = 0; i < count; i++) { p->next = (Info *) malloc(sizeof(Info)); p = p->next; strcpy(p->p, s); } p->next = NULL; return head; } int main() { Info *ts; char *ss; ts = test(); ss = ts->next->p; printf("%s\n",ss); return 0; }虽然还是有点问题,但方法思路大致应该差不多了??