![]() |
|
#1
|
|||
|
|||
Write a C++ program to compress a C++ source fileCompression and Decompression
As I have learned in the C++ source file, the lines have to start with many leading spaces. To save spaces in the saving file (to compress the file), the leading spaces may be counted and store the count as an integer in the beginning of the line followed by the rest of the characters of the line. Example: Assume two ASCII characters are reserved for the integer count. Source file: source.txt No leading spaces on line 1 Five leading spaces on line 2 Fourteen leading spaces on line 3 Two leading spaces on line 4 Compressed file: source.zip 0No leading space on line 1 5Five leading spaces on line 2 14Fourteen leading spaces on line 3 2Two leading spaces on line 4 Write a C++ program to compress a C++ source file, store the compressed file in source.zip, and output to the monitor screen the number of space characters eliminated from the original source file. Assuming that the number of spaces are less than 99, reserve two ASCII characters to store the count. Write a C++ program to uncompress the zip. File previously compressed and store the uncompressed file in source.rcv Note: source.txt and source.rcv must look the same. |
|||
|
#2
|
|||
|
|||
Re: Need Assistance ASAP! (how to write this program code..lost where to start)Where to start:
Code:
|
|
#3
|
|||
|
|||
Re: Need Assistance ASAP! (how to write this program code..lost where to start)can you show me some C++ code, please?
|
|
#4
|
|||
|
|||
Re: Need Assistance ASAP! (how to write this program code..lost where to start)this is what i got:
CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
Re: Need Assistance ASAP! (how to write this program code..lost where to start)Instead of reading the entire file into an array, try reading one line at a time with the getline() method.
CPP / C++ / C Code:
|
|
#6
|
|||
|
|||
Re: Write a C++ program to compress a C++ source filecompiled and tested
post if you need help making the decompression programm too CPP / C++ / C Code:
although for some reason it won't work on MSVC++ because of the stupid strcpy_s, my program keeps ending halfway. CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
Re: Write a C++ program to compress a C++ source fileQuote:
Quote:
CPP / C++ / C Code:
What happens with your program if the line length is, say, 1021 characters? |
|
#8
|
|||
|
|||
Re: Write a C++ program to compress a C++ source filewell, it just said "look" the same, not be the same. The other option would be to store 2 separata variables, 1 for spaces, one for tabs, or to just forget about the tabs and only do the spaces. Witchever way you pick, the result will be both visually, and for the compiler the same whan you compare source.txt to source.rcv
As for the spaces-> tabs conversion, this turns it back to the "way it was". CPP / C++ / C Code:
as for the 999+ characters, I was just continuing the code wrote by fakepoo, if you want I can dinamically alocate memory depending on strlen bla bla..., but these scenarios generally cover theoretical situations, just make it char line [100000];. |
|
#9
|
|||
|
|||
Re: Write a C++ program to compress a C++ source fileQuote:
Quote:
So, considering a line MOSTLY would be around 50-100 characters long, it's okay for you to waste over 99 percent of the allocated space most of the time? And allocate 100000 chars on stack? A line over 999 characters is not a theoretical situation. You see such lines when examining the source code of web pages. One page I quickly looked up was 21000 characters long. |
|
#10
|
|||
|
|||
Re: Write a C++ program to compress a C++ source fileQuote:
criticism noted, and also it looks like I deviated from the original request, I just had to remove spaces, nothing about the tabs although, how would you do the scenario where you had to remove both spaces and tabs?I mean if you have the following sequence CPP / C++ / C Code:
how would the end file look like?(note to not actually take more space than the original ) |
Recent GIDBlog
Problems with the Navy (Officers) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need help C++ program | statquos | C++ Forum | 0 | 06-Jun-2008 08:47 |
| Can you help me solving this program!plzz post the code of this program plzz.. | albert_123 | C Programming Language | 2 | 12-Sep-2006 06:47 |
| Urgent ! Pls Help Me ! | mycashmoney | C Programming Language | 4 | 01-Jul-2006 22:49 |
| [Tutorial] GUI programming with FLTK | dsmith | FLTK Forum | 10 | 03-Oct-2005 15:41 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The