B
bowlderster
Hello,all.
I want to get the array size in a function, and the array is an argument of the function.
I try the following code.
/***************************************
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int upzeroH(double *inputH)
{
int i_data;
for(i_data=0;i_data<1024;++i_data)
printf("%g\n",*(inputH+i_data));
i_data=0;
while((inputH+i_data)!=(double *)0)
++i_data;
printf("Size of input data is %i\n",i_data);
return 0;
}
int main(void)
{
int i,j,row=1024,column=3;
double a[row];
double dt=0.02;
for(i=0;i<row;++i)
{ a=sin(i*dt);
printf("%g\n",a);
}
printf("Size of array a is %i\n",sizeof(a)/sizeof(double));
upzeroH(a);
return 0;
}
/**********************************************
*/
In fact, in the function,the array has been printed successfully by printf statement.
I try to use the while statement to calculate the array size.But it is failed.
I just want to know whether the pointer (inputH+i_data) has reached the end of the array
by while((inputH+i_data)!=(double *)0), but it cannot work.
Is there any sign to indicate the end of an array? which I can use to quit the while loop.
Or, is it better to use another argument nCount=sizeof(a)/sizeof(double) to give the array size
directly?
Thanks for your help.
I want to get the array size in a function, and the array is an argument of the function.
I try the following code.
/***************************************
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int upzeroH(double *inputH)
{
int i_data;
for(i_data=0;i_data<1024;++i_data)
printf("%g\n",*(inputH+i_data));
i_data=0;
while((inputH+i_data)!=(double *)0)
++i_data;
printf("Size of input data is %i\n",i_data);
return 0;
}
int main(void)
{
int i,j,row=1024,column=3;
double a[row];
double dt=0.02;
for(i=0;i<row;++i)
{ a=sin(i*dt);
printf("%g\n",a);
}
printf("Size of array a is %i\n",sizeof(a)/sizeof(double));
upzeroH(a);
return 0;
}
/**********************************************
*/
In fact, in the function,the array has been printed successfully by printf statement.
I try to use the while statement to calculate the array size.But it is failed.
I just want to know whether the pointer (inputH+i_data) has reached the end of the array
by while((inputH+i_data)!=(double *)0), but it cannot work.
Is there any sign to indicate the end of an array? which I can use to quit the while loop.
Or, is it better to use another argument nCount=sizeof(a)/sizeof(double) to give the array size
directly?
Thanks for your help.