Book Cipher

Pages: 12
Well, if you are reading/encoding the entire file, just read the entire file, then just write the encrypted file as you read the old one.
So I do something like:

if ch='a'
{

}

correct?

But then how do I place my variable a inreplace of the character 'a'?

EDIT: actually I have a switch for every letter already but I am still very confused

EDIT EDIT: While I'm at it I might as well mention the other errors I have as well:

infile.open( argv[1].c_str() ); //open book file -- error C2228: left of '.c_str' must have class/struct/union

while ( tolower(infile.get(ch) ) ) - fatal error C1903: unable to recover from previous error(s); stopping compilation -- error C2664: 'tolower' ***FIXED

Couple other errors as well but I'll leave it at this for now



Thanks
Last edited on
argv[1] is already a C-style string (char*)

If you read the entire file into a string, you can use the replace() function.
http://www.cplusplus.com/reference/string/string/replace/
Hey it's been a while since I'veposted here, but anyway, I can't seem to get the replace function working properly. Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
case 'a':
				letternum++;

				if (a.empty())
				{
				letterSs << letternum; 
				wordSs << wordnum; 
				lineSs << linenum; 
				a = lineSs.str() + ':' + wordSs.str() + ':' + letterSs.str() + '.';
				//break;
				}

				//cout << "REPLACING THE LETTER 'A'";
				msgfile.replace(it, it+1, a );
				break;


I get a debug assertion failed error when I run my program and it is the replace funtion causing the error.

How can I fix this?

Thanks
nvm I fixed the replace... but for some reason my program says it finds the letter 'a' more than once.

My file that I am encoding is just abcdefghijklmnopqrstuvwxyz. So there is only one 'a' in the file.

Any suggestions?

Thanks

EDIT: the replace is not fixed... :(
Last edited on
can anyone help me please I have to have this assignment done by thursday :(
Topic archived. No new replies allowed.
Pages: 12