| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1300 人关注过本帖
标题:为什么fidelast函数出错?
取消只看楼主 加入收藏
温酒斩化腾
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2017-3-28
结帖率:72.73%
收藏
已结贴  问题点数:7 回复次数:2 
为什么fidelast函数出错?
#include <stdio.h>
#include <stdlib.h>
typedef struct player
{
    int accont;
    char a[20];
    int power;
    struct player *next;
}PLAYER;
PLAYER *build(int num)
{
    PLAYER *prept,*head;
    int i;
    printf("input information:\n");
    PLAYER *pt=(PLAYER *)malloc(sizeof(PLAYER));
    if(pt!=NULL)
    {
        scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
    }
    else
    {
        printf("error!\n");
        exit(0);
    }
    for(i=1;i<num;i++)
    {
        PLAYER *pt=(PLAYER *)malloc(sizeof(PLAYER));
        if(pt!=NULL)
        {
           scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
        }
        else
        {
            printf("error!\n");
            exit(0);
        }
    }
    return head;
}
PLAYER *fidelast(PLAYER *head)
{
    PLAYER *pt=head;
    while(pt->next!=NULL)
    {
        pt=pt->next;
    }
    return pt;
}
PLAYER *fidenode(PLAYER *head,int num)
{
    int i;
    PLAYER *pt=head;
    for(i=1;i<num&&pt->next!=NULL;i++)
    {
        pt=pt->next;
    }
    return pt;
}
PLAYER *insertlast(PLAYER *head)
{
    PLAYER *prept,*pt;
    pt=(PLAYER *)malloc(sizeof(PLAYER));
    if(pt!=NULL)
        scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
    else
        exit(0);
    prept=fidelast(head);
    prept->next=pt;
    pt->next=NULL;
    return head;
}
PLAYER *insert(PLAYER *head,int num)
{
    PLAYER *prept,*pt;
    pt=(PLAYER *)malloc(sizeof(PLAYER));
    if(pt!=NULL)
        scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
    else
        exit(0);
    prept=fidenode(head,num);
    pt->next=prept->next;
    prept->next=pt;
    return head;
}

int main()
{
    PLAYER *q,*c;
    int a;
    printf("input how many:\n");
    scanf("%d",&a);
    q=build(a);
  
    printf("input what you wan fide:\n");
    scanf("%d",&a);
    c=fidenode(q,a);
    printf("%s",c->next);

}
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: player int next head NULL 
2017-07-01 20:52
温酒斩化腾
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2017-3-28
收藏
得分:0 
回复 3楼 ehszt
#include <stdio.h>
#include <stdlib.h>
typedef struct player
{
    int accont;
    char a[20];
    int power;
    struct player *next;
}PLAYER;
PLAYER *build(int num)
{
    PLAYER *prept,*head,*pt;
    int i;
    printf("input information:\n");
    pt=(PLAYER *)malloc(sizeof(PLAYER));
    if(pt!=NULL)
    {
        scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
        head=pt;
        prept=pt;
    }
    else
    {
        printf("error!\n");
        exit(0);
    }
    for(i=1;i<num;i++)
    {
        PLAYER *pt=(PLAYER *)malloc(sizeof(PLAYER));
        if(pt!=NULL)
        {
           scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
           prept->next=pt;
           prept=pt;
        }
        else
        {
            printf("error!\n");
            exit(0);
        }
    }
    return head;
}

PLAYER *fidenode(PLAYER *head,int num)
{
    int i=1;
    PLAYER *pt=head;
    while(i<num&&pt!=NULL)
    {
        pt=pt->next;
        i++;
    }
    return pt;
}

int main()
{
    PLAYER *q,*c;
    int a;
    printf("input how many:\n");
    scanf("%d",&a);
    q=build(a);
    printf("input what you wan fide:\n");
    scanf("%d",&a);
    c=fidenode(q,a);
    printf("%s",c->next);

}
我把指针的问题改了后为什么还是不对呢,请解释一下,谢谢
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
2017-07-01 23:14
温酒斩化腾
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2017-3-28
收藏
得分:0 
回复 5楼 ehszt
谢谢大佬
2017-07-02 08:44
快速回复:为什么fidelast函数出错?
数据加载中...
 
   



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

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