我有一个问题下了,而在C编码(我没有经验的程序员)的错误。 我有这样函数调用给不兼容的类型参数
struct afreq
{
int freq;
unsigned char sym;
short int left,right,next;
};
在主功能
的结构:
struct afreq data[50] ;
INT大小=操作(数据,计数); //这个功能做一些操作和INT type.And的 回报大小我在下面的函数调用中使用这个尺寸:
dictionary(data,var,size);
创造一部分的问题是在这里:
///////////////////////////// Definition of Dictionary function /////////////////////////////////////////
dictionary(struct afreq data[] ,char *var,size_t dataSize)// function definition create problem in first argument when caled from the another recursive function call inside this function.
dictionary(struct afreq data[] ,char *var,size_t dataSize)
{
int i;
printf("\n data: %d\n", dataSize);
for(i=2;i<dataSize;++i)
{
if(data[i].left=='\0')
{ int correspondance[data[30];
char temp[30];
strcpy(temp, var);
strcat(temp, "0");
printf("check1");
dictionary(data[correspondance[data[i].left]], temp,dataSize); //error here
}
printf("\n");
}
}
我想要什么要用这个吗? 我必须从作为唯一参数给出的文件中读取字母。该文件是“Input.txt”,并包含'abcdef'(我计算它们在我的程序中的频率),然后我将它们保存在格式[symbol Frequency LeftChild RightChild] [例如:[a 1 0 0] [ b 2 0 0] [c 3 ab]等(这就像霍夫曼编码))。 到这里,我已经做好了一切。但是当我尝试打印字典时(如我们在huffman中(o和1中的路径))(在这个例子中,我们可以看到“c”是父项,“a”的路径是“o”和“b”是“1”)。为了实现这个部分,我写了上面的代码,它在函数调用的第一个参数中创建了错误。 下面是完整的代码(但是,请不要忘了包括其中包含“ABCDEF”唯一的参数“INPUT.TXT”文件。
Here is the output:
[email protected]:~/Desktop/Internship_Xav/Task2$ gcc ttask.c -o ttask
improve.c: In function ‘dictionary’:
improve.c:85:2: error: incompatible type for argument 1 of ‘dictionary’
improve.c:74:1: note: expected ‘struct afreq *’ but argument is of type ‘struct afreq’
'数据[我] .left'类型是'短int' – BLUEPIXY
这么多的问题出现。 – Dipto
@BLUEPIXY你有我的问题的任何解决方案(我有责任不使用指针,其他明智我会做ÿ等)你能帮我吗?谢谢。 (一尝试以下豆已确切地理解了我的蚂蚁做的。但如何通过创建表来实现呢?(不是指针)的任何片段或指导吗?)@Dipto感谢您的帮助 – user3085082