so I'm doing
Code:
customer = new char[strlen(acct.customer) + 1];
but than when I copy with
Code:
strcpy(customer, acct.customer);
the end of string does not get copied, right? do I have to add it in there like:
Code:
customer[strlen(acct.customer)+1] = '\0';
???
Here's the rest.
Code:
Account::Account(){
customer = 0;
init(",,,;", "000000000000000", 0);
}
Account::Account(const Account & acct){
printf("is it calling here?");
if (customer) {
delete [] customer;
}
try {
customer = new char[strlen(acct.customer)];
}
catch( bad_alloc) { customer = NULL; }
if(customer){
strcpy(customer, acct.customer);
strcpy(accountNumber, acct.accountNumber);
balance = acct.balance;
}
}
Account::Account(const char c[], const char num[], int b){
cout<<"length of passed string for customer is: "<<strlen(c)<<endl;
customer = new char[strlen(c) + 1];
strcpy(customer, c);
customer[strlen(c) + 1] = '\0';
cleanSpace(customer);
strcpy(accountNumber, num);
balance = b;
}
Account::~Account() {
if(customer) {
delete [] customer;
}
}
void Account::init(const char c[], const char num[], int b){
try {
customer = new char[strlen(c) + 1];
}
catch (bad_alloc) { customer = NULL; }
if(customer){
strcpy(customer, c);
customer[strlen(c) + 1] = '\0';
cleanSpace(customer);
strcpy(accountNumber, num);
balance = b;
}
}
const Account& Account::operator= (const Account & acct){
strcpy(this->customer, acct.customer);
strcpy(this->accountNumber, acct.accountNumber);
this->balance = acct.balance;
return *this;
}
By the way, thanks for the help