SRL Archive - C/C++ Help and Tutorials

Passing an Array as a paramater


TehNeonFishy

2012-11-23 11:56:19

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

2012-11-23 17:52:05

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;

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

Bobarkinator

2012-11-23 18:08:28

Arrays in C are automatically declared as pointers. So if stats is an array, that line needs to be

statsCreation(stats)

Recursive

2013-01-16 19:47:35

You need to use a dynamically allocated array. Or pass a pointer to the array to the function