Bus Error

I believe that a Bus Error is a problem with the program trying access memory it cant. I am not sure what i'm doing wrong. I believe its coming from the strcpy(newAccount, accountNum); and strcpy(newName, name); I am really bad with pointers. could anyone explain this to me.

This is what i have so far

#include <iostream>
#include <string>

using namespace std;

class creditAccount
{
private:
char accountNum[20];
char name[21];
int expMonth;
int expYear;
double limit;
double balance;
public:
creditAccount::creditAccount(char* newAccount, char* newName, int newMonth, int newYear, double newLimit, double newBlance);
double creditAccount::getBalance();
void creditAccount::processPayment(double paymentAmount);
bool creditAccount::processCharge(double chargeAmount);
void creditAccount::Print();
};
creditAccount::creditAccount(char* newAccount, char* newName, int newMonth, int newYear, double newLimit, double newBalance)
{
strcpy(newAccount, accountNum);
strcpy(newName, name);
expMonth = newMonth;
expYear = newYear;
limit = newLimit;
balance = newBalance;
}
double creditAccount::getBalance()
{
return balance;
}
void creditAccount::processPayment(double paymentAmount)
{
balance = balance - paymentAmount;
}
bool creditAccount::processCharge(double chargeAmount)
{

}
void creditAccount::Print()
{
cout << accountNum << " " << name << " " << expMonth << " " << expYear << " " << limit << " " << balance << endl;
}
int main()
{
creditAccount account("1234-5049-7347-3894", "Tim Grable", 8, 2010, 5000.00, 155.75);
account.Print();

return 0;
}

The strcpy() function accept two parameters:
strcpy ( char * destination, const char * source );

If you read your code, you will see that you have the opposite way the destination and the source...
You have as destination the newAccount which is actually the source.
The same for the newName also.

Hope this helps.
Ya that worked thanks
Topic archived. No new replies allowed.