I'm currently working on a project where I want to convert the entries of a CSV file into a vector of Objects. Therefore I have written a function, which converts an array of structs in a vector. The problem is that right now my function only works if the user enters the right size of the array as an additional parameter but if he enters a higher number an exception is thrown because the function is trying to read from an array entry that doesn't exist. Now I want to know if there is anyway that I can determine the size of the array of structs in my function. I have already tried sizeof(array)/sizeof(array[0])
but that doesn't work.
Here is the function I'm talking about:
BANKMANAGEMENT_API int initAccounts(ACCOUNT accArray_[], const int numOfAcc_)
{
BankmanagementClass *myBankmanagement = BankmanagementClass::createBankmanagementClass();
for (int i = 0; i < numOfAcc_; i++)
{
ACCOUNT acc = accArray_[i];
Account* newaccount = Account::accountStruct2Obj(&acc);
myBankmanagement->setNextAccountId(myBankmanagement->determineNextId(newaccount->getAccountId(), myBankmanagement->getNextAccountId()));
myBankmanagement->addAccount(newaccount);
}
LogInfo("Account Vector was initialized with data from Csv File.");
return 0;
}
I want to get rid of the numOfAcc_
parameter so that the user can't enter the wrong size.
It's for a dll with C interface.