小羊爱.睡觉♡ 2023-01-31 15:05 采纳率: 50%
浏览 17

求解这个代码哪里出问题了吗(关键词-#include)

求解这个代码哪里出问题了吗?编译不通过,非常感谢

#include<stdio.h>
#include<string.h>
#define n 5
#define m 2*n-1
typedef struct{
    int weight;
    int parent;
    int lchild;
    int rchild;
}HTNode;
typedef struct{
    char ch;
    char code[n];
}nodecode;
void InitHuffmanTree( HTNode ht[m])
{
    int i=0;
    for(i=1;i<=m;i++)
    {
        ht[i].weight=0;
        ht[i].lchild=0;
        ht[i].rchild=0;
        ht[i].parent=0;
        
    }
}
void Inputweight(HTNode ht[m])
{
    int i=0;
    for(i=1;i<=n;i++)
    {
        printf("请输入第%d个权值:",i);
        scanf("%d",&ht[i].weight);
    }
}
void selectmin(HTNode ht[m],int s1,int s2,int i)
{
    int minweight=100;
    for(i=1;i<=m;i++)
    {
        if((ht[i].weight<minweight)&&(ht[i].parent==0))
            {
                minweight=ht[i].weight;
            }
    }
    s1=i;
    minweight=100;
    for(i=1;i<=m;i++)
    {
        if((ht[i].weight<minweight)&&(ht[i].parent==0)&&(i!=s1))
        {
            minweight=ht[i].weight;
        }
    }
    s2=i;
}
void creatHuffmanTree(HTNode ht[m])
{
    int i=0;
    for(i=n+1;i<=m;i++)
    {
        selectmin(HuffmanTree,s1,s2)
        ht[s1].parent=i;
        ht[s2].parent=i;
        ht[i].lchild=s1;
        ht[i].rchild=s2;
        ht[i].weight=ht[s1].weight+ht[s2].weight;
    }
}
void creatHuffmancode(HTNode ht[m],nodecode code[n])
{
    char arr[n];
    int start,p;
    arr[n]='\0';
    start=n-1;
    printf("请输入字符");
    for(i=1;i<=n;i++)
    {
        scanf("%c",&ncode[i].ch);
        while((p=ht[i].parent)!=0)
        {
            if((ht[p].lchild)==i)
            {
               arr[start]='0';    
            }
            else
            {
                arr[start]='1';    
            }
            start--;    
        }
    strcpy(ncode[i].code,arr);
    }
    printf("\n");
    for(i=1;i<=n;i++)
    {
        printf("第%d个字符%c的编码是%s\n",i,ncode[i].ch,ncode[i].code);
    }
}
int main()
{
    int s1=0;
    int s2=0;
    HTNode HuffmanTree[m];
    nodecode ncode[n];
    InitHuffmanTree(HuffmanTree);
    Inputweight(HuffmanTree);
    creatHuffmanTree(HuffmanTree);
    creatHuffmancode(HuffmanTree,code);
    return 0;
}

  • 写回答

2条回答 默认 最新

  • 於黾 2023-01-31 15:26
    关注

    你这代码问题一大堆,我随便说几个
    selectmin函数需要4个参数,你只传了3个
    printf("请输入字符");这里分号是全角的
    for(i=1;i<=n;i++)变量i没有定义
    -=-=-=-
    话说,IDE里已经给你指出错误在哪一行了,你一个一个的去解决掉就好,不要老指望别人
    此外,写一段代码就编译一下,把错误解决掉,不要等攒了100个错误一起解决

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 1月31日

悬赏问题

  • ¥15 matlab生成的x1图不趋于稳定,之后的图像是稳定的水平线
  • ¥15 请问华为OD岗位的内部职业发展通道都有哪些,以及各个级别晋升的要求
  • ¥20 微信小程序 canvas 问题
  • ¥15 系统 24h2 专业工作站版,浏览文件夹的图库,视频,图片之类的怎样删除?
  • ¥15 怎么把512还原为520格式
  • ¥15 MATLAB的动态模态分解出现错误,以CFX非定常模拟结果为快照
  • ¥15 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
  • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET