From 24fa4b350bb006f236ac47dcba3f81ed96a50a34 Mon Sep 17 00:00:00 2001
From: Eduardo Machado <emm14@inf.ufpr.br>
Date: Fri, 20 Nov 2015 15:19:11 -0200
Subject: [PATCH] funcionando por enquanto

---
 include/lzw.h |  2 +-
 src/lzw.cpp   | 11 +++++------
 src/main.cpp  |  3 +--
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/include/lzw.h b/include/lzw.h
index d76e347..2373a75 100644
--- a/include/lzw.h
+++ b/include/lzw.h
@@ -12,4 +12,4 @@
 using namespace std;
 
 int* pack(string input);
-string unpack(int* input);
\ No newline at end of file
+string unpack(int* input, int size);
\ No newline at end of file
diff --git a/src/lzw.cpp b/src/lzw.cpp
index 975f394..1abb35f 100644
--- a/src/lzw.cpp
+++ b/src/lzw.cpp
@@ -40,10 +40,10 @@ int* pack(string input){
 
 }
 
-string unpack(int* input){
+string unpack(int* input, int size){
 	map<int, string> dictionary;
 	string currentChar, nextChar, output = "";
-	int i, size, dictionarySize = 256;
+	int i, dictionarySize = 256;
 	int currentWord, nextWord;
 
 	//inicializa o dicionário
@@ -53,19 +53,18 @@ string unpack(int* input){
 
 	nextWord = input[0];
 	output += dictionary[nextWord];
-	size = sizeof(input)/sizeof(int);
-	for(i = 0; i < size; i++){
+	for(i = 0; i < size-1; i++){
 		currentWord = nextWord;
 		nextWord = input[i+1];
 		if(dictionary[nextWord] != ""){
 			output += dictionary[nextWord];
 			currentChar = dictionary[currentWord];
-			nextChar = dictionary[nextWord][1];
+			nextChar = dictionary[nextWord][0];
 			dictionary[dictionarySize] = currentChar + nextChar;
 			dictionarySize++;
 		}else{
 			currentChar = dictionary[currentWord];
-			nextChar = dictionary[currentWord][1];
+			nextChar = dictionary[currentWord][0];
 			output += currentChar + nextChar;
 			dictionary[dictionarySize] = currentChar + nextChar;
 			dictionarySize++;
diff --git a/src/main.cpp b/src/main.cpp
index f3601c8..6bb21d6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -59,8 +59,7 @@ int main(int argc, char *argv[])
 		}
 
 		// Descompactação.
-		outputUnpack = unpack(inputUnpack);
-		cout << "outputUnpack = " << outputUnpack << endl;
+		outputUnpack = unpack(inputUnpack, length/4);
 
 		// Escrita no arquivo de saída.
 		fileOut.open(nameFileOut.c_str(), ios::out);
-- 
GitLab