本文介绍了如何将数组中的特定元素内容存储到另一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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]);
}
这个我有一个数组(thxcross_pos [sample_length])里面有元素,这里我也创建了一个更多数组(PZLoctn [PZLoctn_counter]),其大小可能因条件而异,这里我打算将thxcross_pos [] == 1的索引存储到PZLoctn [] den到PZdemo
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
推荐答案
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]);
}
这篇关于如何将数组中的特定元素内容存储到另一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!