Click here to Skip to main content
15,895,011 members

Comments by Lones (Top 3 by date)

Lones 22-Dec-21 15:50pm View    
also changing my codes to this

fseek(file, 0, SEEK_END);
long count = ftell(file);
fseek(file, 0, SEEK_SET);

solved 00 00 00 problem but now decompressing fails

Message: hello world this is a trial
Compressed version: E8 32 9B FD 06 DD DF 72 36 19 44 47 A7 E7 A0 F4 1C 14 06 D1 E5 E9 30
Decompressed version: hello world this is a tria
Compression crushed!

decompression doesn't take last letter
Lones 22-Dec-21 15:32pm View    
Thanks a lot for answer, sorry but what did you mean by 1) one creating message with malloc

char Message[count] = (long*)malloc(count *sizeof(long));

I tried like this but compiler says "error: variable-sized object may not be initialized" however even if it would accept I think this would be already pointless because you said "if count is larger than maximum stack size, you can corrupt other variables already on the stack" I couldn't figure out how to create array Message with malloc also with limit of count,
sorry my questions might be bad or ridiculous, I'm very new to programming (just been 2 months) and only used C and C++ till now
Lones 22-Dec-21 13:20pm View    
strlen(Message) returns 27 which is equal to character numbers in .txt file

Message[count]='\0'; I added this because compressing was crushing before it, it was adding some U*? strange chars at the end of file (I assume program was not seeing end of the file)