下面是求编码函数,为什么用#if 0和endif 之间的代码替换静态数组就不行呢?用静态数组可以求的结果,怎么要是改成动态char **c这种形式程序就死啊
,退不出来啊!
static void Coding(Huffman T[], int N)
{
 char c[20][20] = {'\0'};
 int i, j, k, step, father;
 #if 0
 char **c;
 if (((c = (char**)malloc(sizeof(char*) * N))) == NULL)
 {
  exit(1);
 }
 for (i = 0; i < N; i++)
 {
  if (((c[i] = (char*)malloc(sizeof(char) * (N + 1)))) == NULL)
  {
   exit(1);
  }
 }
 for (i = 0; i < N; i++)
 {
  for (j = 0; j < N + 1; j++)
  {
   c[i][j] = '\0';
  }
 }
 #endif
 for (i = 0; i < N; i++)   /* get every node code */
 {
  step = i, k = 0;
  father = T[step].parent;
  while (father != -1)
  {
   if (T[father].lchild == step)
   {
    c[i][k++] = '0';
   }
   else
   {
    c[i][k++] = '1';
   }
   step = father;
   father = T[step].parent;
  }
 }
 printf("The Coding Is:\n");
 for (j = 0; j < N; j++)
 {
  printf("%s\n", c[j]);
 }
}



											

	    

	