为什么会是死循环啊??
程序代码:
#include <stdio.h> #include <stdlib.h> #include <string.h> struct people { char name[30]; struct people *next; }; struct people *input(struct people *h); void print(struct people *h); //主函数 int main() { struct people *head=NULL; head=input(head); print(head); return 0; } //输入函数 struct people *input(struct people *h) { struct people *p_one, *p_two; p_one=p_two=(struct people*)malloc(sizeof(struct people)); if(p_one!=NULL) { scanf("%s",p_one->name); p_one->next=NULL; } while(p_one->name[0]!='#') //若想终止输入,则在输入姓名的时候输入# { if(h==NULL) h=p_one; else p_two->next=p_one; p_two=p_one; p_one=(struct people *)malloc(sizeof(struct people)); while(p_one->name!=NULL) { scanf("%s", p_one->name); p_one->next=NULL; } } return h; } //输出函数 void print(struct people *h) { struct people *temp; temp = h; while(temp != NULL) { printf("%s", temp->name); temp = temp -> next; } }
[ 本帖最后由 thlgood 于 2011-3-19 17:12 编辑 ]