Feb 13, 2009 at 10:56pm UTC
I am trying to write a function that takes 1 dim arrays of various lengths and initializes them to zero.
I am planning to call the function multiple times, to it only has to handle one array at a time.
I have been trying to use these 2 methods:
void setZero(int array1[])
{
for (int row=0;!array1;row++)
{
array1[row]=0
}
//or
void setZero (int array1[])
{
array1[x]={0};
}
does anyone have any suggestions about the '!array' format, or another possible option?
Thanks
Feb 13, 2009 at 11:11pm UTC
Neither version will work.
void zero(int *array,int size);
Feb 13, 2009 at 11:15pm UTC
Yes, as helios said...you MUST pass the size, unless it a null-terminated char*, then you can use strlen()...but other then that, there is no way to know the size.
Feb 13, 2009 at 11:17pm UTC
thanks for the reply
so there is no way to set all values of an array to zero without also passing its size?
Feb 13, 2009 at 11:18pm UTC
sorry... ignore the question, i did not refresh.
Thanks