decode-celejuk4-1n4glsqh.c
#include
#include
#include
#include
typedef struct DLListNode {
int value;
char chars[10];
} DLNodeList;
DLNodeList *newDLNodeList(char c[], int it)
{
DLNodeList *new;
new = malloc(sizeof(DLNodeList));
assert(new != NULL);
new->value = it;
strcpy(new->chars, c);
return new;
}
int get_len(char string[]){
for(int m=0;m<100;m++){
if (string[m] == '\0'){
return m;
}
else{
printf("ERROR");}
}
return 100;
}
int compare(DLNodeList *nodes[], char chars[]){
for(int m=0;m<1000;m++)
{
if (strcmp(chars, nodes[m]->chars)== 0){
return 1;
}
}
return 0;
}
void print_nodes(DLNodeList *nodes[]){
int m = 0;
while (nodes[m]->value != -1){
printf("Index: %d. Value: %s\n",nodes[m]->value, nodes[m]->chars);
m++;
}
}
int search_str(DLNodeList *nodes[], char string[]){
int m =0;
while(m<1000){
if (strcmp(nodes[m]->chars, string) == 0){
return nodes[m]->value;
}
m++;
}
return 0;
}
char *search_value(DLNodeList *nodes[], int val){
int m =0;
while(m<1000){
if (nodes[m]->value == val){
return nodes[m]->chars;
}
m++;
}
return "no";
}
//Main function of LZW
int main(int argc, char *argv[]) {
char var[100];
int k = 0;
while(k <100){
var[k] = '0';
k++;
}
DLNodeList *nodes[1000];
int m = 0;
while(m<1000){
nodes[m] = newDLNodeList("\0", -1);
m++;
}
char str[1000];
fgets(str, 1000, stdin);
int length = strlen(str);
DLNodeList *string[1000];
m = 0;
while(m<1000){
string[m] = newDLNodeList("\0", -1);
m++;
}
m = 0;
char delim[] = " ";
char *ptr = strtok(str, delim);
int modi = 0;
while(ptr != NULL)
{
if (strlen(ptr) != 1){
strcpy(string[modi]->chars,ptr);
string[modi]->value = 2;
modi++;
}
else{
strcpy(string[modi]->chars,ptr);
string[modi]->value = 1;
modi++;
}
ptr = strtok(NULL, delim);
if (strcmp(ptr,"\n")== 0){
break;
}
}
m = 0;
int index = 256;
int last_mod = 0;
while(m
{
if(m == 0){
char W[10] = {"\0"},K[10] = {"\0"}, output[10] = {"\0"}, symbol[10] ={"\0"}, real_W[10] = {"\0"};
strcpy(K,string[m]->chars);
if (argc != 1){printf("NIL %s %s \n",K,K);}
else{printf("%s",K);}
}
else if (string[m]->value == 1 && string[m-1]->value == 1){
char W[10] = {"\0"},K[10] = {"\0"}, output[10] = {"\0"}, symbol[10]...