substitution cypher

I need to a line of input from a file, echoprint the original line, decrypt it using a substitution cipher, then output the decoded line. So it would be like this:
original line 1
decoded line 1
original line 2
decoded line 2
original line 3
decoded line 3
etc...

The maximum characters per line is 70, so I'm trying to count each character on a line, then use a subarray to put that line into an array so I can then decode it.

I am stuck at putting just one line into an array. I could put the whole line into one, but I have no idea how to just use one line at a time. Any tips?
Last edited on
It's impossible to make suggestions without seeing your code.
This is what I have right now
1
2
3
4
5
6
7
8
9
10
11
12
13
char ch = 0;
do
{
	inFile.get(ch);
	ch++;
}while ( ch != '/n');


	//get line from file
	for ( count = 0; count < ch; count++)
	{
		inFile >> lineFromFile[count];
	}
Last edited on
line 4: You're not testing for eof

line 5: Why are you incrementing the character just read?

Lines 2-6: You not storing the characters you have read anywhere.

Line 10: Your termination condition in the for loop is comparing count to the last character read by the do/while loop, which will always be a newline character.

Line 12: There is no need to keep an array of lines. You only need to process one line at a time.

This is really very simple:
1
2
3
4
5
6
7
8
  string ciphertext;    
  string cleartext;    

  while (inFile.getline (ciphertext))
  {  cout << ciphertext << endl;
      Decrypt (ciphertext, cleartext);
      cout << cleartext << end;
  }




Last edited on
I am getting an error "no instance of overloaded function matches the argument list" on the getline?
Sorry. getline is specialization of string. The istream method takes a char array.
http://www.cplusplus.com/reference/string/string/getline/
http://www.cplusplus.com/reference/istream/istream/getline/

1
2
3
4
5
6
7
8
 string ciphertext;    
  string cleartext;    

  while (getline (inFile, ciphertext))
  {  cout << ciphertext << endl;
      Decrypt (ciphertext, cleartext);
      cout << cleartext << end;
  } 






Last edited on
.
Last edited on
.
Last edited on
Topic archived. No new replies allowed.