I'm recieving strange errors that I think are being caused by how I've included my files.
If this is a incorrect way to structure my include files then please tell me a correct method.
there are three files:
Code:
#include <iostream>
#include <vector>
#include <fstream>
#include <cstring>
using std::cout;
using std::cin;
using std::string;
using std::endl;
using std::ifstream;
using std::ofstream;
using std::vector;
#include "decryptor.h"
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Code:
class decryptor
{
public:
decryptor();
~decryptor(){}
void getTripNum(char*);
void fillFromFile();
void tryPassKey();
int findSamuel(); //returns 1 for true and zero if false
private:
vector<int> tripNumInts;
int currentPasskey;
string output;
};
#include "decryptor.cpp"
Code:
decryptor::decryptor()
{
currentPasskey = 0;
output = '\0';
}
void decryptor::fillFromFile()
{
char* fileName = "Xencryption.xe";
char* temp = 0;
char* rawTriple = "";
int count = 0;
ifstream fin(fileName);
while (!fin.eof())
{
while(count < 3)//while we don't have a threesome of numbers; continue
{
fin.getline(temp,5,'.');
if (temp) //if We got a valid number
{
strcat(temp,"."); //add back in the period
strcat(rawTriple,(const char*)temp);//now add it to rawTriple
count++; //and let us know how many numbers rawTriple Has
}//if
}// while
getTripNum(rawTriple);
count = 0; //for starting over
rawTriple = "";
}//while
return;
}//function()
//data comes to this function looking like this: 234.51.-234.
void decryptor::getTripNum(char* rawData)
{
char* oneNum;
char* twoNum;
char* thrNum;
int finalNum = 0;
oneNum = strtok(rawData, "."); //snag first number
twoNum = strtok(rawData, "."); //snag second number
thrNum = strtok(rawData, "."); //snag third, as if that wasn't obvious...
finalNum += atoi(oneNum);//add all together
finalNum += atoi(twoNum);
finalNum += atoi(thrNum);
tripNumInts.push_back(finalNum); //and save it
return;
}//function()
void decryptor::tryPassKey()
{
while (!findSamuel()) //does this Passkey work?
{
unsigned int charIter = 0;
int testch = 0;
while (charIter < tripNumInts.size()) //converts
{
testch = (tripNumInts[charIter] - currentPasskey);
if (testch > 255 || testch <0)
{
output = "";
if (testch > 255)
{
output = "failed to find Samuel in all possible Ranges"; //since we've been increased the passkey slowly we must have failed : (
return;
}
else
currentPasskey += testch; //bring passkey in range
}//if
output += (char)testch; //add to decrypted output
}//while
currentPasskey++; //try next one
}//while
return;
}//function()
int decryptor::findSamuel()
{
unsigned int Iterator = 0;
while(Iterator < tripNumInts.size()) //loop while we don't have 'S'
{
if( ((int) 'S') == (tripNumInts[Iterator] - currentPasskey) )//if we found 'S'then check for the rest
{
Iterator++;
if( ((int) 'a') == (tripNumInts[Iterator] - currentPasskey) )//if there is an 'a' after it
{
Iterator++;
if( ((int) 'm') == (tripNumInts[Iterator] - currentPasskey) )
return 1; //found Sam
}//if
}//if
Iterator++;
}//while
return 0; //nope no sam :-(
}//function
here are the errors:
Code:
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|1|error: `decryptor' has not been declared|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|2|error: ISO C++ forbids declaration of `decryptor' with no type|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp||In function `int decryptor()':|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|3|error: `currentPasskey' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|4|error: `output' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|3|warning: unused variable 'currentPasskey'|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|4|warning: unused variable 'output'|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|7|error: `decryptor' is not a class or namespace|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp||In function `void fillFromFile()':|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|13|error: `ifstream' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|13|error: expected `;' before "fin"|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|15|error: `fin' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|23|error: `strcat' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|29|error: `getTripNum' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|29|warning: unused variable 'getTripNum'|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|9|warning: unused variable 'fileName'|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|13|warning: unused variable 'ifstream'|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|39|error: `decryptor' is not a class or namespace|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp||In function `void getTripNum(char*)':|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|46|error: `strtok' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|50|error: `atoi' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|54|error: `tripNumInts' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|54|warning: unused variable 'tripNumInts'|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|59|error: `decryptor' is not a class or namespace|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp||In function `void tryPassKey()':|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|61|error: `findSamuel' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|66|error: `tripNumInts' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|68|error: `currentPasskey' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|71|error: `output' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|80|error: `output' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|80|warning: unused variable 'output'|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|82|error: `currentPasskey' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|82|warning: unused variable 'currentPasskey'|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|61|warning: unused variable 'findSamuel'|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|89|error: `decryptor' is not a class or namespace|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp||In function `int findSamuel()':|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|93|error: `tripNumInts' was not declared in this scope|
C:\Documents and Settings\*****\My Documents\Test programs\crash\WingC\XDecrypt\decryptor.cpp|95|error: `currentPasskey' was not declared in this scope|
||=== Build finished: 24 errors, 9 warnings ===|
Edit: All the errors occurred in the last file