Hello,
I want to check the length of an array say ARR[100]. Lets assume that after some computations it has 30 values stored in it from ARR[0] to ARR[29]. How do i determine its length?. I am typically expecting an answer of 30.
Thanks,
prads
how to check the length of an array
Page 1 of 12 Replies - 799 Views - Last Post: 01 February 2008 - 05:35 AM
Replies To: how to check the length of an array
#2
Re: how to check the length of an array
Posted 01 February 2008 - 04:32 AM
prads, on 1 Feb, 2008 - 04:28 PM, said:
Hello,
I want to check the length of an array say ARR[100]. Lets assume that after some computations it has 30 values stored in it from ARR[0] to ARR[29]. How do i determine its length?. I am typically expecting an answer of 30.
Thanks,
prads
I want to check the length of an array say ARR[100]. Lets assume that after some computations it has 30 values stored in it from ARR[0] to ARR[29]. How do i determine its length?. I am typically expecting an answer of 30.
Thanks,
prads
one way could be to keep a counter which will be incremented every time you add a value in array. in another way you can initialize array with some value which you expect never to occur after calculations. and after you finish with your computation, just run a loop till you get that value, the loop counter will give you the length.
I think first way can be good enough for you as second looks like additional logic to be added. I can't think of any other good logic for this right now.
#3
Re: how to check the length of an array
Posted 01 February 2008 - 05:35 AM
When you init your array, clean it out.
Now that it's empty, every time that you write a value to ARR, you can check for '\0', & you know you've hit the end of your input.
char ARR[100];
int i=0;
for(i=0;i<=100;i++) {
ARR[i]='\0';
}
Now that it's empty, every time that you write a value to ARR, you can check for '\0', & you know you've hit the end of your input.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|