Click here to Skip to main content
15,896,478 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
int thresholdcount,PZLoctn_counter;
float *PZdemo;
for(thresholdcount=0;thresholdcount<sample_length;thresholdcount++)
{
 if(thxcross_pos[thresholdcount]==1)
	{
	//PZLoctn[thresholdcount]=thxcross_pos[thresholdcount];
	PZLoctn[thresholdcount]=thresholdcount;
	printf("pzloctn:%f\n",PZLoctn[thresholdcount]);
	PZdemo=PZLoctn[thresholdcount];
	PZLoctn_counter=PZLoctn_counter+1;	
	}

}
for(thresholdcount=0;thresholdcount<PZLoctn_counter;thresholdcount++)
{
printf("%f\n",PZdemo[thresholdcount]);
}


in this i have an array(thxcross_pos[sample_length]) which contents elements and here i have also create one more array(PZLoctn[PZLoctn_counter]) whose size may varies according to the condition, here i am planning to store the index of thxcross_pos[]==1 into PZLoctn[] den to PZdemo
Posted
Updated 14-Jan-15 2:12am
v2

1 solution

The problem seems that you have not allocated memory to PZDemo. Check below code for your starting point

C
int thresholdcount,PZLoctn_counter;
float *PZdemo = new float[sample_length];
for(thresholdcount=0;thresholdcount<sample_length;thresholdcount++)
{
 if(thxcross_pos[thresholdcount]==1)
    {
    //PZLoctn[thresholdcount]=thxcross_pos[thresholdcount];
    PZLoctn[thresholdcount]=thresholdcount;
    printf("pzloctn:%f\n",PZLoctn[thresholdcount]);
    PZdemo=PZLoctn[thresholdcount];
    PZLoctn_counter=PZLoctn_counter+1;
    }

}
for(thresholdcount=0;thresholdcount<PZLoctn_counter;thresholdcount++)
{
printf("%f\n",PZdemo[thresholdcount]);
}
 
Share this answer
 
Comments
mybm1 14-Jan-15 8:27am    
Actually PZdemo size is not determine because it is going to store only the index/position of thxcross_pos whose value is ==1.
Simple i just want an array which content only the index of thxcross_pos[] whose value is ==1.

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