Pointer or &

Jul 14, 2013 at 9:09pm
The program should have a menu that allows the user to perform the following tasks:

1. To enter the source file name.
2. To enter the destination file name.
3. To encrypt from the source to the destination file.
4. To decrypt from the source to the destination file.

I used a switch statement for this program. I don't know how to allow the user to create a filename (1&2) but I can access the file names during encryption and decryption.

case 1:
cout<<"Enter the input file name";
cin>>input;
case 2:
cout<<"Enter the out file name";
cin>>out ;

How do I pass those file names to case 3 and 4 for the encryption/decryption?
using &? *?
Thanks.
Jul 14, 2013 at 9:25pm
Can you simply rewrite your menu? For example

1. To encrypt from the source to the destination file.
2. To decrypt from the source to the destination file.
3. Exit

And if the user select either #1 or #2 then ask him

Enter the source file name: bla..bla..bla
Enter the destination file name: bla...bla...bla

Last edited on Jul 14, 2013 at 9:26pm
Jul 14, 2013 at 11:32pm
no it has to be these 4 options
Jul 15, 2013 at 3:05am
pointer (*) or dereference (&) pretty much have the same function with different interface
so it's just a matter of preferences

Anyway how do you plan on using the pointer
it's just easier to pass the string

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

void decrypt( const string& in, const string& out ){
// your code here
}

int main(){
string infilename, outfilename;
int inputInt;

cin >> inputInt;

switch( inputInt ){
case 1:
cin >> infilename;
break;
case 2:
cin >> outfilename;
break;
case 3:
encrypt( infilename, outfilename );
break;
case 4:
decrypt( infilename, outfilename );
break;

}
}


Haven't test my own code
but it should look something like that if that what you want, I think
Topic archived. No new replies allowed.