| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 246 人关注过本帖
标题:为什么会是死循环啊??
取消只看楼主 加入收藏
thlgood
Rank: 5Rank: 5
等 级:职业侠客
帖 子:281
专家分:381
注 册:2010-9-24
结帖率:91.43%
收藏
已结贴  问题点数:20 回复次数:0 
为什么会是死循环啊??
程序代码:
#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 编辑 ]
2011-03-18 22:15
快速回复:为什么会是死循环啊??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016660 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved