Here is my code
double hour_payload_add(int entries , double array[])
{
int index=0 ,k=0;
int totalpayload=0;
double returnarray[entries/120];
while(k< entries)
{
totalpayload = totalpayload + array[k];
if(k%120==0)
{
returnarray[index] = totalpayload;
index++;
totalpayload=0;
}
}
return returnarray;
}
here I have called it
double hourgraph[hrentries];
hourgraph= hour_payload_add(entries , graph);
as I want to return an array what should I do to return without using pointers?
Pass the array by reference to the function and don't return anything. Small example:
void hour_payload_add(int entries , double array[], double (&returnArray)[SIZE])
{
// returnArray will be updated as it's external to function.
}
or
void hour_payload_add(int entries , double array[], double *returnArray) // <-- pointer
{
// returnArray will be updated as it's external to function.
}
usage:
double returnArray[SIZE];
hour_payload_add(entries, array, returnArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With