943,776 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 5306
  • C++ RSS
Nov 26th, 2008
-1

Need sample code for Text File Compression!!!

Expand Post »
Need some help on text file compression....
Text File Compression.

The text file compression must be able to perform the following functions:

• Able to compress a text file and generate an index file
• Able to decompress the file
• Able to show the time taken for compressing and decompressing
• Able to show the file size before and after compressed






Task:
1) Replace repeated sentence with index number
2) Decompress into original text file
3 )Use class
4) Replace repeated words with index number
5) Use any 2 concepts of OOD (i.e. inheritance, polymorphism)
6) Comment methods and variables appropriately
7) Generate Index file that store index number and correspondent word/sentence
Last edited by SlayerX; Nov 26th, 2008 at 4:24 am.
Similar Threads
Reputation Points: 8
Solved Threads: 0
Newbie Poster
SlayerX is offline Offline
4 posts
since Nov 2008
Nov 26th, 2008
0

Re: Need sample code for Text File Compression!!!

911: http://www.daniweb.com/forums/announcement8-2.html
Sample code needed? Google is your friend!..
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Nov 26th, 2008
0

Re: Need sample code for Text File Compression!!!

can giv me a sample?thx or help me with it .....i will learn it myself or u can write comment for me to let me learn it in the code....
Last edited by SlayerX; Nov 26th, 2008 at 12:34 pm.
Reputation Points: 8
Solved Threads: 0
Newbie Poster
SlayerX is offline Offline
4 posts
since Nov 2008
Nov 26th, 2008
0

Re: Need sample code for Text File Compression!!!

You know, I've been wondering about this for awhile now myself.

Honestly you can probably get away with making some kind of regex or key to "compress" files with given values.

For example lets say you have a text document and it is set up something like this--

// myWord.txt

ssssss      
ss

-- what is listed is 6 s's, then 6 space characters, then a newline character and then 2 s's. After those s's, the end-of-file character is present (not in the above example, but pretend it is there for the sake of this example @_@ ).

How would you compress this? Right now the amount of space this file takes up on a disk is between (6 * 1 + 6 * 1 + 6 * 2 + (1 or 0)) or 24-25 bytes to 4096 bytes (4 kb) due to the way expansions work on some disk drives. If you want to compress this file to take up less space, you can form a special key that detects multiple values of a particular character and places them in an index.

For example, there are 6 s's. You can make a .compress file such that it has a pair of numbers (like 1 and 6) such that they are read from a parser that you will create that takes an index file of the same name for a particular .compress file and maps the numbers to their corresponding characters in the index file.

Your index file might look something like this--

s//[s char]
// [newline char] //[space char]s//[s char]

--and if you have a smart parser, you can do repetition-detection for a particular character such that you don't need to index the same character more than once. Your index file would then look like--

s//[s char]
// [newline char] //[space char]

--the job of your compress file is simply to have a number (or a key) match with a value and for a given position of the cursor the appropriate amount of values will be placed in appending order from the cursor's location.

The only down-side to this technique is that if you have too many individual data values in your file (that are non-recurring or not consecutive), you may face an expansion instead of a compression when you try to compress the file.

This is just a theory, but hopefully it helps.

-Alex
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Nov 26th, 2008
0

Re: Need sample code for Text File Compression!!!

In the case the you only had to use ASCII values 32-126, you then could share a single byte for two values. You could even use a truth table that points out the positions of a nibble that is really its opposite extended version 128-255.
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
MosaicFuneral is offline Offline
1,270 posts
since Nov 2008
Nov 27th, 2008
-1

Re: Need sample code for Text File Compression!!!

oh..thx guys.....but i still cant do it....need some beginning codes...as u know im still beginner....well..hope u can help me thx!!
Reputation Points: 8
Solved Threads: 0
Newbie Poster
SlayerX is offline Offline
4 posts
since Nov 2008
Nov 27th, 2008
0

Re: Need sample code for Text File Compression!!!

Click to Expand / Collapse  Quote originally posted by SlayerX ...
oh..thx guys.....but i still cant do it....need some beginning codes...as u know im still beginner....well..hope u can help me thx!!
You are NOT going to get a code solution. Either give in trying or post what you think you should be doing in words, pseudo-code or some method of displaying what you think you have to do. Then we can help you from there.

@everyone else
Hmm this makes interesting reading thanks

Chris
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Nov 27th, 2008
1

Re: Need sample code for Text File Compression!!!

Get nice and comfortable, this is a long read
http://www.faqs.org/faqs/compression-faq/
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Nov 28th, 2008
0

Re: Need sample code for Text File Compression!!!

If i know how to do...do u think i will post here??...jus giv me a starting point......i really dont know how to do only post here...
Reputation Points: 8
Solved Threads: 0
Newbie Poster
SlayerX is offline Offline
4 posts
since Nov 2008
Nov 29th, 2008
1

Re: Need sample code for Text File Compression!!!

Tell me, can you even write a program to copy a file one character at a time?

Or write a program which can say count the number of 'a' characters in a file?

Or even produce a histogram showing the distribution of letters in a file?
See, having done this, you're half-way there to fulfilling one of your program requirements.

Because the same old plz help, gimme the codez refrain isn't doing you any favours at all.

a) we're not going to give you the complete answer
b) we're not going to give you much help until YOU post some code. When you post code, we know where to start with the explanations.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC