Click here to Skip to main content
15,913,090 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for(j=0;j<e1;j++)
{
index1=PZLoctn1[j];
index2=NZLoctn1[j];
printf("\n%d\t%d\n",index1,index2);
	
	for(i=index1;i<index2;i++)
		{
		   pz2nz[0][i]=kld_smooth_norm[i];
		  // printf("pz2nz:%f\n",pz2nz[0][i]);	
		}
		  
}

here kld_smooth_norm[80,000] and the index1 index2 will be changing for each loop
first loop index1=12612 index2=14521
2nd loop index1=16029 index2 =23753
3rd loop index1=31387 index2= 55794
4th loop index1=62933 index2=68856
and in pz2nz i want to store all the element for each loop from index1 t oindex2
can someone tell me how to declare the size of pz2nz for storing the elements
Posted

Don't use an array, use one of the Collection classes[^].

[edit]
Apologies I misread C for C#. You can make an array dynamic in C by allocating it at run time via malloc[^].

[/edit]
 
Share this answer
 
v3
Comments
nv3 17-Jan-15 5:55am    
Op is talking about C, not C#.
Richard MacCutchan 17-Jan-15 6:05am    
Oops!
There is no way to declare an array in C, the size of which is unknown at compile-time. Instead you can use malloc / free to allocate storage dynamically and assign its address to a pointer.

Allocating storage takes some time and it is advisable to avoid allocating / freeing storage in a high frequency, for example in a loop. In your case that seems to be possible easily: Determine in a first loop the maximum length needed and then allocate that storage once.

Another observation here, is that you seem to use only small index intervals in each loop, for example 62933 ... 68856. In such a case it may pay off to just allocate an array for that index interval, 5924 cells in that case, and recalculate the index with which you access that array.

In C++ the job would be somewhat easier as you could make use of classes like vector, which does much the storage management for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900