I did some searching and I think it might be a buffer overflow but I'm not sure. Could someone tell me what's wrong with this?
SafeGuard:: SafeGuard(int agent)
{
for(int index = 0; index < 26; index++)
{
upperCase[index] = 'A' + index;
lowerCase[index] = 'a' + index;
}
for(int alter = 0; alter < 26; alter++)
{
shiftedUpper[alter] = upperCase[(1 + agent) * 9 )% 26];
shiftedLower[alter] = lowerCase[(1 + agent) * 9 )% 26];
}
cout<<"Upper Case: "<<upperCase<<endl;
cout<<"Lower Case: "<<lowerCase<<endl;
cout<<"Shifted upper case: "<<shiftedUpper<<endl;
cout<<"Shifted lower Case: "<<shiftedLower<<endl;
}
======================class header===============
#ifndef CLASS_SafeGuard_
#define CLASS_SafeGuard_
#include <iostream>
#include <string>
using namespace std;
class SafeGuard
{
private:
char upperCase[26];
char lowerCase[26];
int shift;
char shiftedUpper[26];
char shiftedLower[26];
char message[100];
public:
SafeGuard::SafeGuard(int shift);
char *encrptMessage(char message[]);
char *decryptMessage(char message[]);
char *getMessage();
int getShift();
};
#endif
For some reason when I output upperCase it contains the values stored in it as well as the values stored in lowerCase. The same thing for shiftedUpper. What's going on here?
P.S My professor says it has something to do with the memory locations. For some reason in the class putting shift in between two char arrays remedies the problem.
Additional Details
When I added the null character the lowerCase char array won't display anything.