http://forums.d2jsp.org/topic.php?t=70760193&f=122&p=475144111Quote
ur fucnction has 3 parameters and u call it with 2
what is the point of last param (a) ?
Also u should be able to make it with just one param (the array)
u can calculate the length of it in the function
sizeof (x) / sizeof (x[0])
This is wrong. When you pass an array to any function you pass its pointer which is always either 4 or 8 bytes long. So infact when you tried to use his method of finding the array size inside a funciton it would actually return the size of the pointer address and not the actual data.
Here is an example of why it is wrong:
Code
#include <stdio.h>
#include <stdlib.h>
void test(int array[]);
int main() {
int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
printf("Size of array outside of funciton is: %d\n", sizeof(a) / sizeof(a[0]));
test(a);
return 0;
}
void test(int array[]) {
printf("Size of array inside of function is: %d\n", sizeof(array) / sizeof(array[0]));
}
Size of array outside of funciton is: 9
Size of array inside of function is: 1
Process returned 0 (0x0) execution time : 0.034 s
Press any key to continue.
When passing an array in C you must always pass the length of it as well unless it is an array of fixed length, even then you should pass it anyways.
@OP: Your call to the funciton is failing because you have a useless variable (int a) inside the funciton prototype at the top. Remove it as it is not being used and your code will compile.
From abduct