I'm trying to set up a charArray array to load info from a file into and use ==, != operators and so on on it. Here is my test file:
//test.cpp
//chrArray test file
#include "chrArray.h"
#include <iostream>
using namespace std;
void main(){
chrArray newChar(10);
cout << newChar.getCharArray() << endl;
newChar = "hi";
cout << newChar.getCharArray() << endl;
bool testOut = (newChar=="hi"
cout << testOut << endl;
testOut = (newChar=="by"
cout << testOut << endl;
testOut = (newChar!="hi"
cout << testOut << endl;
testOut = (newChar!="by"
cout << testOut << endl;
newChar.setCharArray("Goodbye"
cout << newChar.getCharArray() << endl;
}
###########################################################
Here is the output that I get:
10
4
²²²²¦¦¦¦¦¦¦
hi
1
0
0
1
Good ²²²²¦¦¦¦¦¦¦
Press any key to continue
###########################################################
the top two numbers are the size of array that should be created and the size that is created. Whatever size I try and create I only seem to get one 4 long and any strings longer than 3 I get strange results. What am I doing wrong.
Here is my specification file:
//chrArray.h
//chrArray header file
class chrArray{
private:
char *chrArrayPointer;
int size;
public:
chrArray(int intArrayLength);
~chrArray();
bool operator==(char charArrayComp[]);
bool operator!=(char charArrayComp[]);
void operator=(char charArraySet[]);
char *getCharArray();
void setCharArray(char charArraySet[]);
};
###########################################################
and the implementation file:
//chrArray.cpp
//chrArray Implementation file
#include "chrArray.h"
#include <iostream>
using namespace std;
chrArray::chrArray(int intArrayLength){
cout << intArrayLength << endl;
chrArrayPointer = new char[intArrayLength];
for (int i = 0; i < intArrayLength; i++){
chrArrayPointer = ' ';
}
size = sizeof(chrArrayPointer)/sizeof(char);
cout << sizeof(chrArrayPointer) << endl;
}
chrArray::~chrArray(){
delete chrArrayPointer;
}
bool chrArray:perator==(char charArrayComp[]){
int loopCount;
int intCompArrayLength = sizeof(charArrayComp) / sizeof(char);
if (intCompArrayLength < size){
loopCount = intCompArrayLength;
}else{
loopCount = size;
}
for (int i =0; i < loopCount; i++){
if (chrArrayPointer != charArrayComp){
return false;
}
}
return true;
}
bool chrArray:perator!=(char charArrayComp[]){
if (*this==charArrayComp){
return false;
} else {
return true;
}
}
void chrArray:perator=(char charArraySet[]){
int loopCount;
int intCompArrayLength = sizeof(charArraySet) / sizeof(char);
if (intCompArrayLength < size){
loopCount = intCompArrayLength;
}else{
loopCount = size;
}
for (int i = 0; i < loopCount; i++){
chrArrayPointer = charArraySet;
}
}
char *chrArray::getCharArray(){
return chrArrayPointer;
}
void chrArray::setCharArray(char charArraySet[]){
*this = charArraySet;
}
###########################################################
Hope you guys can help.
Thanks
Giles Giles Roadnight
messenger: giles_roadnight@hotmail.com
ICQ: 81621370
//test.cpp
//chrArray test file
#include "chrArray.h"
#include <iostream>
using namespace std;
void main(){
chrArray newChar(10);
cout << newChar.getCharArray() << endl;
newChar = "hi";
cout << newChar.getCharArray() << endl;
bool testOut = (newChar=="hi"
cout << testOut << endl;
testOut = (newChar=="by"
cout << testOut << endl;
testOut = (newChar!="hi"
cout << testOut << endl;
testOut = (newChar!="by"
cout << testOut << endl;
newChar.setCharArray("Goodbye"
cout << newChar.getCharArray() << endl;
}
###########################################################
Here is the output that I get:
10
4
²²²²¦¦¦¦¦¦¦
hi
1
0
0
1
Good ²²²²¦¦¦¦¦¦¦
Press any key to continue
###########################################################
the top two numbers are the size of array that should be created and the size that is created. Whatever size I try and create I only seem to get one 4 long and any strings longer than 3 I get strange results. What am I doing wrong.
Here is my specification file:
//chrArray.h
//chrArray header file
class chrArray{
private:
char *chrArrayPointer;
int size;
public:
chrArray(int intArrayLength);
~chrArray();
bool operator==(char charArrayComp[]);
bool operator!=(char charArrayComp[]);
void operator=(char charArraySet[]);
char *getCharArray();
void setCharArray(char charArraySet[]);
};
###########################################################
and the implementation file:
//chrArray.cpp
//chrArray Implementation file
#include "chrArray.h"
#include <iostream>
using namespace std;
chrArray::chrArray(int intArrayLength){
cout << intArrayLength << endl;
chrArrayPointer = new char[intArrayLength];
for (int i = 0; i < intArrayLength; i++){
chrArrayPointer = ' ';
}
size = sizeof(chrArrayPointer)/sizeof(char);
cout << sizeof(chrArrayPointer) << endl;
}
chrArray::~chrArray(){
delete chrArrayPointer;
}
bool chrArray:perator==(char charArrayComp[]){
int loopCount;
int intCompArrayLength = sizeof(charArrayComp) / sizeof(char);
if (intCompArrayLength < size){
loopCount = intCompArrayLength;
}else{
loopCount = size;
}
for (int i =0; i < loopCount; i++){
if (chrArrayPointer != charArrayComp){
return false;
}
}
return true;
}
bool chrArray:perator!=(char charArrayComp[]){
if (*this==charArrayComp){
return false;
} else {
return true;
}
}
void chrArray:perator=(char charArraySet[]){
int loopCount;
int intCompArrayLength = sizeof(charArraySet) / sizeof(char);
if (intCompArrayLength < size){
loopCount = intCompArrayLength;
}else{
loopCount = size;
}
for (int i = 0; i < loopCount; i++){
chrArrayPointer = charArraySet;
}
}
char *chrArray::getCharArray(){
return chrArrayPointer;
}
void chrArray::setCharArray(char charArraySet[]){
*this = charArraySet;
}
###########################################################
Hope you guys can help.
Thanks
Giles Giles Roadnight
messenger: giles_roadnight@hotmail.com
ICQ: 81621370