PDA

View Full Version : Passing an Array as a paramater



TehNeonFishy
11-23-2012, 04:56 PM
I'm passing an array as a argument into a procedure. I'm stuck with an error.


statsCreation(stats[ASIZE]);

argument of type "int" is incompatible with parameter of type "int*"

I haven't used pointers anywhere. Anyone know what the problem is? =/


OR you could maybe help with me the problem itself, I need to check to make sure the sum of an array is within two integers.

KingKong
11-23-2012, 10:52 PM
paste the whole code that is relevant to that line. for addition of the array just loop through the array and add them one by one?

for (int i=0;i<len;++i) total +=arr[i];

if (total >= lownum && total <= highnum) dosomething;

Bobarkinator
11-23-2012, 11:08 PM
Arrays in C are automatically declared as pointers. So if stats is an array, that line needs to be


statsCreation(stats)

Recursive
01-17-2013, 12:47 AM
You need to use a dynamically allocated array. Or pass a pointer to the array to the function