Program for coding/decoding text from file. Problem is with decoding last symbol. First is good. Have no ideas where is wrong. Pehaps you do. Thanx a lot. :s
really look nice. Thanx. I'll try it combine with program.
So. tried it. Its bugged - on writting to "answer.txt" program die...
Visible is reading coded text and no information about encoding :) so, I din't know decoding or not or still did not write :) can You explain why program die?
This error report includes: information regarding the condition of *.exe when the problem occured; the operating system version and computer hardware in use; your Digital Product ID, which could be used to identify your license; and the Internet Protocol (IP) address of your computer.
This happened when I put code for changing first and the last characters in place:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
if (str.length() == 0) continue;
cout << "\nCoded txt: " << str << endl;
{
char s = str[0]; //|\ first become s
str[0] = str[n]; //|- last become first
str[n] = s; //|/ value s become last
for (int i = 1; i < str.length(); i += 2)
{
char s = str[i];
str[i] = str[i-1];
str[i-1] = s;
}
#include <iostream>
#include <fstream>
usingnamespace std;
#include "supply.h"
int main()
{
ofstream file1("Decode.txt");
// Make a new file, test if ok
if (!file1)
{
cout << "Error " << "file, ";
cout << "Can not open file." << "\n";
return (1);
}
// write the content to disk and close the file
cout << "Type in the content you wish to write in file\n";
char buffer[255];
cin.getline( buffer, 255);
file1 << buffer;
file1.close();
// read the file, edit letters in decode function
char ch;
cout << "\nReading the content of file...\n";
ifstream code("Decode.txt");
ofstream input("Encode.txt");
while (code.get(ch) ) {
decode(ch); // editing letter
input << ch;
cout << ch;
}
cout << "\nEncode complete\n";
code.close();
input.close();
system("Pause");
return 0;
}
// My functions --
char decode( char & character)
{
// first four characters opposite to the next four
// check for matches
if (character == 'a')
return character = 'e';
if (character == 'b')
return character = 'f';
if (character == 'c')
return character = 'g';
if (character == 'd')
return character = 'h';
if (character == 'e')
return character = 'a';
if (character == 'f')
return character = 'b';
if (character == 'g')
return character = 'c';
if (character == 'h')
return character = 'd';
// first
if (character == 'i')
return character = 'm';
if (character == 'j')
return character = 'n';
if (character == 'k')
return character = 'o';
if (character == 'l')
return character = 'p';
if (character == 'm')
return character = 'i';
if (character == 'n')
return character = 'j';
if (character == 'o')
return character = 'k';
if (character == 'p')
return character = 'l';
// sceond
if (character == 'q')
return character = 'u';
if (character == 'r')
return character = 'v';
if (character == 's')
return character = 'w';
if (character == 't')
return character = 'x';
// third
if (character == 'u')
return character = 'q';
if (character == 'v')
return character = 'r';
if (character == 'w')
return character = 's';
if (character == 'x')
return character = 't';
// last are special
if (character == 'y')
return character = '-';
if (character == 'z')
return character = '+';
if (character == '-')
return character = 'y';
if (character == '+')
return character = 'z';
return character = '#'; // default value
}