outputting decoded line from a file

Ok so I have this function, I can get it to display the original line by line but i cant get it to display the decrypted line. I think line 16 in the Decrypt function is the problem, but i dont know how to fix it.

It is supposed to read out like this, and the first line of the file I open is the key for the substitution cypher

original line
decoded line
original line
decoded line
etc etc..

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

//original alphabet
		cout << endl << "Original Alphabet:  ";
	int x = 0;
	for ( char i = 'A'; i <= 'Z'; i++)
	{
		alphabet[x++] = i;
	}

	for (int i = 0; i < 26; i++)
	{
		cout << alphabet[i];
	}
	//encrypted alphabet
	
	int count;
	cout << endl << "Encrypted Alphabet: ";
	for (count = 0; count < SUBCIPHER; count++)
	{
		inFile >> fixedSub[count];
	}
	for (int i = 0; i < 26; i++)
	{
		cout << fixedSub[i];
	}

while (getline (inFile,cipherText))
	{
		cout << cipherText << endl;
		Decrypt (cipherText, fixedSub);
		//cout << clearText << endl;
	}

This is the Decrypt function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void Decrypt(string encrypted, char subCode[])
{
	int c;
	char array[80];
	int charInLine = encrypted.length();
	for ( c=0; c <= charInLine; c++)
	{
		array[c] = encrypted[c];
	}

	for (c = 0; c <charInLine; c++)
	{
		array[c] = subCode[c];
	}

	cout << array[charInLine] << endl;

	return;
}
Last edited on
Please don't create new topics when your old topic is so recent (and the same subject).
http://www.cplusplus.com/forum/beginner/128139/
Topic archived. No new replies allowed.