求助~~没有错误提示,就是无法正常运行,求各位牛人指导!
这是我写的LZW的压缩算法,编译,链接都没有错误,就是运行不下去,请各位帮忙指点一下吧~~多谢了!!#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
void compress_f(void);
void display_f(void);
char getcode(char *t);
struct dictionary{
char data[256]; //二进制数据
char code; //字典代码
struct dictionary *next;//节点指针
struct dictionary *pro;
};
struct dictionary *head,*the,*first;//头指针、当前指针
void main ( )
{
system("cls");
compress_f();
display_f();
}
void compress_f()//LZW
{ int i,j;
char d[256],c[256];
char p[256],s,t[256];//前缀、后缀、当前字符
printf("请输入二进制数:");
scanf("%s",d);
head=(struct dictionary*)malloc(sizeof(struct dictionary));
sprintf(p,"%c",d[0]);
the=head->next;
the->pro=head;
first=head;
strcpy(the->data,p);
the->code=':';
p[0]='\0';
j=1;
for(i=1;i<256;i++)
{ the=(struct dictionary*)malloc(sizeof(struct dictionary));
the=head->next;
head=the->pro;
sprintf(p,"%s%c",p,d[i-1]);
s=d[i];
sprintf(t,"%s%c",p,s);
if(getcode(t))
c[i]=getcode(t);
else
{strcpy(the->data,t);
the->code=head->code;}
}
printf("压缩代码为:%s\n",c);
}
char getcode(char *t)
{
dictionary *p;
char *y;
p=first->next ;
while(p!=NULL)
{
y=p->data;
if(strcmp(y,t)==0)
return(p->code);
else p=p->next ;
}
}
void display_f(void)
{
int count=0;
printf("data code\n");
printf("-----------\n");
the=head->next;
while(the!=NULL)
{
printf(" %-20s%3s\n",the->data,the->code);
count++;
the=the->next;
}
}