I have the following code below. It can successfully convert .txt files to LZW compressed files, however, when I run it on a .jpg (which should in theory work). The first char/int it reads is "255", then strcat() tries to concatenate k_str to wk on the second loop which should in theory be "216 or \330". Wk_ptr == "\377", incomplete sequence \330 . I'm not sure what the issue is.
Thanks
void encode(FILE *in, FILE *out) {
unsigned char w[ENTRYSIZE] = "";
unsigned char *w_ptr = w;
unsigned char wk[ENTRYSIZE] = "";
unsigned char *wk_ptr;
unsigned char k;
unsigned char k_str[2];
unsigned int c;
unsigned int i;
for (i = 0; i < ASCII; i++) {
dict[i][1] = i;
dict[i][0] = 1;
}
while ((c = fgetc(in)) != EOF) {
k_str[0] = c;
k_str[1] = '\0';
w_ptr = w;
strcpy(wk, w_ptr);
strcat(wk, k_str);
wk_ptr = wk;
if (check_dict(wk_ptr, 0) == 1) {
strcpy(w, wk_ptr);
} else {
write12(out, check_dict(w_ptr, 1));
add_dict(wk_ptr);
k_str[0] = c;
k_str[1] = '\0';
strcpy(w, k_str);
}
}
write12(out, check_dict(w_ptr, 1));
flush12(out);
write12(out, check_dict(w_ptr, 1));
}