| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 407 人关注过本帖
标题:请问下大神,这个为什么会错。麻烦调释下。。
取消只看楼主 加入收藏
dengluoy
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:127
专家分:165
注 册:2013-2-5
结帖率:94.44%
收藏
已结贴  问题点数:20 回复次数:0 
请问下大神,这个为什么会错。麻烦调释下。。
程序代码:
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
struct horse
{
    int age;
    int height;
    char name[20];
    char father[20];
    char mother[20];
    struct horse *next;
};
int main(void)
{
    struct horse *current;
    struct horse *first;
    struct horse *previous;
    char test = '\0';
    for(;;)
    {
        printf("请问想填写马匹的资料吗(Y or N):");
        scanf(" %c",&test);
        if(tolower(test) =='n')
            break;
        current = (struct horse*)malloc(sizeof(struct horse*));
        if(current == NULL)
            continue;
        if(first == NULL)
            first = current;
        if(previous != NULL)
            previous->next = current;
        printf("请输入马匹的名字:");
        scanf("%s",current->name);
        printf("请输入%s的age:",current->name);
        scanf("%d",&current->age);
        printf("请输入%s的height:",current->name);
        scanf("%d",&current->height);
        printf("请输入%s的father名字:",current->name);
        scanf("%s",current->father);
        printf("请输入%s的mother的名字:",current->name);
        scanf("%s",current->mother);
        current->next = NULL;
        previous = current;
    }
    current = first;
    while(current != NULL)
    {
        printf("马匹的名字叫做%s,它的年龄是%d,它的身高是%d.\n",current->name,current->age,current->height);
        printf("他的爸爸叫做%s,他的妈妈叫做%s\n",current->father,current->mother);
        previous = current;
        current = current ->next;
        free(previous);
    }
    return 0;
}
搜索更多相关主题的帖子: mother color 
2013-03-07 22:46
快速回复:请问下大神,这个为什么会错。麻烦调释下。。
数据加载中...
 
   



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

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