N
nooneinparticular
I sat down last night and decided to try and teach myself something
about programming in C++. I have always had an interest in it, so I
went for it. This is what I have to show for my efforts.
What I came up with is simply nothing more than a text
encrypter/decrytper of kindergarden proportions
My problem is this - anytime the prog goes through it's routine, which
it does rather well - the out put of the decryption always stutters
the last character. If the last word is
this
it will always come out with
thisss
It repeats the last char twice. Please pardon any stupidity in my
questions (see above). Here is the source:
// This is an encyrption/decryption program. Nothing fancy - it is a
file i/o
// learning exercise. it is a VERY VERY crude version. I will make it
more
// modular and "proper" as I learn more.
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
string iFilename;
string oFilename;
char in_ch;
char out_ch;
ifstream iFile;
cout << "Please tell me the name of the Input File:\n";
cin >> iFilename;
iFile.open(iFilename.c_str());
if (! iFile.is_open())
{
cout << iFilename << " does not exist. Exiting now.\n\n";
cout << "Press enter to exit...";
cin.get();
return 1;
}
ofstream oFile;
cout << "Give me a name for the output file:\n";
cin >> oFilename;
oFile.open(oFilename.c_str());
if (! oFile.is_open())
{
cout << oFilename << "is not getting opened for some
reason.\n";
cout << "Exiting now.\n\n";
cout << "Press enter to exit...";
cin.get();
return 1;
}
while (! iFile.eof())
{
iFile.get(in_ch);
out_ch = ~in_ch;
oFile << out_ch;
}
iFile.close();
oFile.close();
cout << "Press enter to exit...";
cin.get();
return EXIT_SUCCESS;
}
about programming in C++. I have always had an interest in it, so I
went for it. This is what I have to show for my efforts.
What I came up with is simply nothing more than a text
encrypter/decrytper of kindergarden proportions
My problem is this - anytime the prog goes through it's routine, which
it does rather well - the out put of the decryption always stutters
the last character. If the last word is
this
it will always come out with
thisss
It repeats the last char twice. Please pardon any stupidity in my
questions (see above). Here is the source:
// This is an encyrption/decryption program. Nothing fancy - it is a
file i/o
// learning exercise. it is a VERY VERY crude version. I will make it
more
// modular and "proper" as I learn more.
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
string iFilename;
string oFilename;
char in_ch;
char out_ch;
ifstream iFile;
cout << "Please tell me the name of the Input File:\n";
cin >> iFilename;
iFile.open(iFilename.c_str());
if (! iFile.is_open())
{
cout << iFilename << " does not exist. Exiting now.\n\n";
cout << "Press enter to exit...";
cin.get();
return 1;
}
ofstream oFile;
cout << "Give me a name for the output file:\n";
cin >> oFilename;
oFile.open(oFilename.c_str());
if (! oFile.is_open())
{
cout << oFilename << "is not getting opened for some
reason.\n";
cout << "Exiting now.\n\n";
cout << "Press enter to exit...";
cin.get();
return 1;
}
while (! iFile.eof())
{
iFile.get(in_ch);
out_ch = ~in_ch;
oFile << out_ch;
}
iFile.close();
oFile.close();
cout << "Press enter to exit...";
cin.get();
return EXIT_SUCCESS;
}