So, I've done a little reading and consulted help from a friend. And I think I get it? Actually, my part in the project is just to store the table of characters and frequencies into a linked list. I've written down some codes, so is it possible if anyone can improve it.
Sample Input .txt file (the table of characters and frequencies):
B1
D3
E7
J9
The struct:
struct node {
char info;
int freq;
struct node * next;
struct node * left, *right, *father;
};
typedef struct node * nodeptr;
nodeptr getnode(){
return malloc(sizeof(struct node));
}
The main program (just until the part of storing the table into a linked list):
string input;
nodeptr list = NULL;
FILE *fopen();
int c;
list = fopen("Huffman Table.txt","r");
c = getc(input) ;
while (c!= EOF)
{
putchar(c);
c = getc(input);
}
getch();
fclose(input);
for (node * row = table; row != NULL; row = row->next){
fprintf(file, "%s %i %i", row->info, row->freq);
}
I'm not sure about this part though:
for (node * row = table; row != NULL; row = row->next)
Should I just use this instead?
for(i=0;i<strlen(input);i++){