-3

I'm coding the adaptive huffman algorithm and i have a problem. Reading a JPG file byte after byte i eventually bump on this hex value 00. Which my program reads as '0'.

Check the picture: http://shrani.si/f/u/Ub/3Yv2Q0LA/napaka.jpg

AS you see, the first two chars are represented with a value before the char. -somenumber 'char'.

In the third case, just the zero is passed trought, but my algorithm doesnt do anything with it, as it is not representive as char. How could i fix this, i need to store also these values into my tree so i can compress and eventually decompress.

Cheers

4

1 回答 1

2

Achar是一个数字(在大多数系统上它是一个 8 位数字,但不是全部)。您所看到的是 IDE 使用单引号 ASCII 字符等效显示数值。并非所有字符都映射到可打印的 ASCII 字符(有关更多信息,请参见此处)。

如果 IDE 认为没有可打印的等价物,它就不会费心打印单引号的等价物。当您在代码中将某些内容放在单引号中时,您是在告诉编译器将该字符替换为等价的数字 ASCII。因此以下是等价的:

#include<stdio.h> // C
#include<cstdio>  // C++
int main()
{
  char x = 'A';
  char y = 65;
  if (x == y)
  {
    printf("var x is the same as y. '%c' == '%c'\n", x, y);
  }
  else
  {
    printf("ERROR: var x is different then y. '%c' == '%c'\n", x, y);
  }
}

输出将是:

var x is the same as y. 'A' == 'A'
于 2013-06-05T17:54:18.600 回答