Unable to open a file with i/ofstream

I'm trying to write an [inefficient/insecure] form of encryption/decryption software. I have the encryption down and it looks beautiful. But the decryption software doesnt open the file I want. It creates the right file and writes to it, but it doesnt seem to open the source file. Im not good with i/ostreams. What am I doing wrong? I'm sure this is just a logic error.

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
 int Decryption(char *save, int key, char ExtractedFile[])
{
	char line[10000];
	ofstream EncryptFile(save);
	ifstream EncryptedFile;
	EncryptedFile.open(ExtractedFile);
	if (EncryptedFile.is_open())
	{
		while (!EncryptedFile.eof())
		{
			EncryptedFile.getline(line, 10000);
			strlwr(line);
			int index = 0,
				addition = 0;
			char newchar;
			while (line[index] != 0)
			{
				newchar = line[index];

				if (isalpha(line[index]))
				{
					newchar -= key;
					if (newchar < 'a')
					{
						addition = key % 26;
						newchar = 'z' - addition;
					}
				}
				EncryptFile << newchar;
				index++;
			}
			EncryptFile << endl;
		}
	}
	else
	{
		cout << "Error" << endl;
	}
	cout << endl;
	return 0;
}
int main()
{
	bool repeat = true;
	char choice,
		file[100] = {},
		save[100] = {},
		OutputE[50] = {},
		OutputD[50] = {};
	int key = 123;

	while (repeat == true)
	{
		cout << "Would you like to encrypt or decrypt your document?" << endl;
		cout << "Enter E for encrypt and D for decrypt: ";
		cin >> choice;

		if (choice == 'E' || choice == 'e')
		{
			cout << "What file would you like to use?: <<<Encoding.txt>>>";
			cin >> file;

			cout << "What is the name of the file you wish to save your encryped text to? " << endl;
			cout << "Any spaces should be input as '_' " << endl;
			cout << "Type '.txt' at the end to save to a word document: ";
			cin >> OutputE;

			cout << "Please enter a string of numbers as your encryption key." << endl;
			cin >> key;

			Encrypt(file, key, OutputE);
			cout << "Remember! Your encryption key is <" << key << ">. Dont forget it!" << endl;
			repeat = false;
		}
		else if (choice == 'D' || choice == 'd')
		{
			cout << "What file would you like to decrypt? Please include the extention: ";
			cin >> OutputE;

			cout << "What is the name of the file you wish to save your decryped text to? " << endl;
			cout << "Any spaces should be input as '_' " << endl;
			cout << "Type '.txt' at the end to save to a word document: ";
			cin >> save;

			cout << "To decrypt your file, please enter your key: ";
			cin >> key;
			Decryption(save, key, OutputD);
			repeat = false;
		}
		else
		{
			cout << "That is an invalid move\n" << endl;
			repeat = true;
		}
	}
	return 0;
}


PS: The <<<Encoding.txt>>> is just for bug testing.
Try changing line 16.

while (line[index] != '\0') // '\0' is the terminating null char
Thank you however I've already fixed everything in Decryption (I just havent shown it on here). My question was about how to open my file.
How open, Im guessing you mean how to read your already existing file.

Watch video 64-67(69) and you'll learn how to both create a file, and open/read one - https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83
@TieRein

Don't you already know how to open a file? That's what you do in your Decryption() function.
Topic archived. No new replies allowed.