decompressing an input file? also do while troubles...

how do i decompress an input file and write the results into an output file?

also my do while loop is supposed to keep going unless the user selects the option to exit the program, instead it exits after finishing ay of the options...help?

here's my code so far...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

int main()
{
    int selection; // menu choice made by user
    string filename;
    ifstream inFile;
    ofstream outFile; 
    
    cout << endl << string(41,'*') << endl;
    cout << string(9,'*') << " ";
    cout << " File Compression Menu " << string (9,'*') << endl;
    // option 0
    cout << "0. Exit Program\n";
    // option 1
    cout << "1. Decompress File\n";
    // option 2
    cout << "2. Compress File\n";
    // option 3
    cout << "3. Future Use #1\n";
    cout << string (41,'*') << endl;


    //n main a loop is used to continually prompt 
    //the user to make a selection from the menu. 
    // The loop and the program terminate when the user enters in 0.

    do
    {
        cout << "\nInput  your selection: "; 
        cin >> selection;
        cout << selection << endl;
        if (selection < 0 || selection > 3)
        {
            cout << "Invalid selection made.  Try Again\n";
        }
    } while(selection < 0 || selection > 3);
                                            
	// error message for all non integer characters
	if (cin.fail())
	{
      cin.clear();                     
      cout << string(8,'*') << " Invalid Character Error " << string(8,'*');
      cout << endl << "==> Invalid character entered.\n";
      cout << "==> Please enter 0, 1, 2 or 3.\n";
      cout << string(41,'*') << endl;
    }


	// if-then-else-if statements for processing choice made
	if (selection == 0)
    {
        cout << "\nQuit selected. Terminating program now...\n";
        exit(1);
    }
    else if (selection == 1)
    {
        cout << "\n==> Decompression of a file selected.\n\n";
        cout << "Enter the name of the input file: ";
        cin >> filename;
        cout << filename << endl << endl;
        inFile.open(filename.c_str());
        	if(!inFile)
        	{
        		cout << string(12, '*') << " ";
        		cout << " File Open Error " << string(12, '*') << endl;
        		cout << "==> Input file could not be opened.\n";
        		cout << "==> Decompression has been canceled...\n";
        		cout << string(41,'*') << endl;
        		inFile.clear();
        		return 1;
        	}
    	cout << "Enter the name of the output file: ";
    	cin >> filename;
    	cout << filename << endl << endl;
    	outFile.open(filename.c_str());
    	cout << "==> File has been succesfully decompressed." << endl;
    }
    else if (selection == 2)
    {
        cout << endl << string(41,'*') << endl;
        cout << "==> Compression of a file selected.\n";
        cout << "==> This option is currently unavailable\n";
        cout << string(41,'*') << endl;
    }
    else if (selection == 3)
    {
    	cout << string(41,'*') << endl;
    	cout << "==> No Action Performed\n";
    	cout << "==> This option has been seet aside\n";
    	cout << "==> for future actions\n";
    	cout << string(41,'*') << endl;
    }
    else
    {
        cout << "\n===> Logic error some where."
             << "Seleciton is an invalid value\n";
    }






    return 0;
}
What do you mean by decompressing a file? Do you have zip files? Or something else?
As for why it exits, move line 42 to the end, say line 107. Otherwise the only thing that is repeated is whatever is inside the do..while structure
Topic archived. No new replies allowed.