Posted by: login November 18, 2004
LZ77 Help!
Login in to Rate this Post:     0       ?        
And the Main program!! int main(void) { unsigned char ch ; int i = 0 ,n ; char input[10], infile_name[1024], outfile_name[1024], choice ; printf("\n*************LZ77 MENU*************\n") ; printf("-----------------------------------") ; printf("\nc - Compress File") ; printf("\nd - Decompress File") ; printf("\n-----------------------------------\n") ; printf("\nEnter Choice -> ") ; fgets(input, sizeof(input), stdin) ; while(input[0] != 'c' && input[0] != 'C' && input[0] != 'd' && input[0] != 'D') { printf("\nEnter Choice -> ") ; fgets(input, sizeof(input), stdin) ; } choice = input[0] ; p_start = (unsigned char *)calloc(2 * SW_SIZE + LA_SIZE, sizeof(unsigned char)) ; /* allocates memory for 2*SW*LA */ if(p_start == NULL) { printf("\n***CALLOC FAILED***\n") ; exit(0) ; } p_la = p_la_start = p_start + SW_SIZE ; p_sw = p_start ; p_flag = p_la + SW_SIZE ; switch(choice) { case 'c': case 'C': printf("\nEnter file to compress -> ") ; gets(infile_name) ; while(infile_name[0] == NULL) { printf("\nEnter file to compress -> ") ; gets(infile_name) ; } f_input = fopen(infile_name,"rb+") ; /* opens the file if it exists */ if(f_input == NULL) { printf("\n***FILE NOT FOUND***\n") ; exit(0) ; } printf("\nEnter file to compress to -> ") ; gets(outfile_name) ; while(outfile_name[0] == NULL) { printf("\nEnter file to compress to -> ") ; gets(outfile_name) ; } f_output = fopen(outfile_name,"wb+") ; if(f_output == NULL) { printf("\n***ERROR CREATING OUTPUT FILE FOR COMPRESSION***\n") ; exit(0) ; }
Read Full Discussion Thread for this article