简体   繁体   English

霍夫曼编码-伪EOF

[英]Huffman Coding - Pseudo EOF

I have coded the huffman tree without problems but now I look to add the Pseudo EOF in the file and tree so I know when to stop reading from the file. 我已经对霍夫曼树进行了编码,没有问题,但是现在我希望在文件和树中添加伪EOF,这样我就知道何时停止从文件中读取。

I fully grasp the concept of the Pseudo EOF. 我完全掌握了伪EOF的概念。 I also understand that there are no characters with an ASCII value of > 255. 我也了解没有ASCII值> 255的字符。

What I don't fully understand is the adding of that character to the input file. 我不完全了解的是将该字符添加到输入文件中。 If it has to be a non-ASCII character (because they can be in the file) then what character am I supposed to add to indicate EOF? 如果必须是非ASCII字符(因为它们可以在文件中),那么我应该添加什么字符来表示EOF?

I'm not sure you do really understand what a "pseudo EOF" is all about. 我不确定您是否真的了解“伪EOF”的全部含义。

First, as per the comments, there is no ASCII char greater than 256. Nor is one needed. 首先,根据注释,没有大于256的ASCII字符,也不需要。

What you are being asked to do is to simulate this in code. 您被要求做的是在代码中对此进行模拟。 Say you have a function that reads a character: 假设您有一个读取字符的函数:

int getchar(fhandle);

This function will return values from 0 to 255 to represent ASCII characters. 此函数将返回0到255之间的值以表示ASCII字符。 It can also return a special value such as -1 to indicate end of file. 它还可以返回一个特殊值,例如-1,以指示文件结束。 This special value is the "pseudo EOF". 此特殊值是“伪EOF”。

This character is not in the file. 该字符不在文件中。 It is returned by the function when there are no more characters in the file. 当文件中没有更多字符时,由函数返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM