Hi,
Im having some trouble with the function and I hope some one can help.
The function is supposed to go through an class array and loop for an empty spot. If it finds one its copies data to the data members.
Otherwise it creates a temporary array and copies the values and dynamically increases the array size by 10 and then it copies back the data from the temporary array.
My problem is that once I create the dynamic array I am stuck in the for loop and the arraysize keeps increaseing.
const char* Bank::operator+=(const char data[]){
int i = 0;
const int len = arraySize;
Account *temp;
temp = NULL;
temp = new Account[len];
int bal;
char anum[15 + 1];
char cust[315 + 1];
sscanf(data,"%15[^,],%d,%315[^;];", anum, &bal, cust);
int value = strlen(cust);
cust[value] = ';';
cust[value + 1] = '\0';
cout << "1: " <<arraySize << endl;
while(savings[i].accountNumber != NULL){
i++;
}
if(savings[i].accountNumber == NULL){
strcpy(savings[i].accountNumber, anum);
savings[i].balance = bal;
strcpy(savings[i].customer, cust);
size++;
cout << "2: " << arraySize << endl;
}
else{
while(i < arraySize){
strcpy(temp[i].accountNumber, savings[i].accountNumber);
temp[i].balance = savings[i].balance;
strcpy(temp[i].customer, savings[i].customer);
i++;
}
delete [] savings;
savings = new Account[arraySize + 10];
i = 0;
for(i; i < len; i++){
strcpy(savings[i].accountNumber, temp[i].accountNumber);
savings[i].balance = temp[i].balance;
strcpy(savings[i].customer, temp[i].customer);
}
delete [] temp;
}
strcpy(savings[i].accountNumber, anum);
savings[i].balance = bal;
strcpy(savings[i].customer, cust);
size++;
arraySize = arraySize + 10;
return data;
}