remplir un tableau avec un autre
Bonjour,
j'ai un tableau par exemple de taille 20 remplie la manière suivante: 0 1 ...19.
Je vodrais prendre un élément sur 2 de ce tableau et le remplir dans un autre tableau. Ce nouveau aura une taille de 10. J'ai un problème au niveau du 2ème tableau.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
#include "dvbt_cic_v01.h"
DVBTCic *CreateDVBTCic() {
DVBTCic *DC;
/* Memory allocation for structure DVBTCic. */
DC = (DVBTCic *)calloc(1, sizeof(DVBTCic));
if (!DC) {
printf("\nERROR !\tCreateDVBTCic : unable to allocate memory for DVBTCic structure.\n\n");
exit(EXIT_FAILURE);
}
return (DC);
}
void FreeDVBTCic(DVBTCic *DC) {
/* Test structure existence. */
if (!DC) {
printf("\nWARNING !\tFreeDVBTCic : structure DVBTCic does not exist.\n\n");
return;
}
/* Memory release. */
free(DC);
return;
}
void UseDVBTCic(DVBTCic *DC)
{
int nombre_etages;
signed long decimation;
signed long entree[20];
signed long sortie[20];
int i;
printf("\nNombre d'étages du CIC :");
scanf("%d",&nombre_etages);
for(i=0;i<20;i++)
{entree[i]=i;
printf(" %d",entree[i]);
}
CicNum_stages(DC, nombre_etages);
printf("\n");
for(i=0;i<20;i++)
{
if (i%2)
{decimation=CicDecimate(DC,entree[i],1);
sortie[i]=decimation;
}
else
{sortie[i]=0;
// sortie[i-1]=sortie[i];
// decimation=CicDecimate(DC,entree[i],0);
}
}
for(i=0;i<20;i++)
{
printf(" %d",sortie[i]);
}
return;
}
int CicInit(DVBTCic *DC, int n)
{
int a;
return(a);
}
void CicNum_stages(DVBTCic *DC, int n)
{
int i;
DC->stages = n;
free(DC->nacc);
free(DC->diff);
free(DC->prev);
DC->nacc=(signed long*)malloc(sizeof(int)*(n));
DC->diff=(signed long*)malloc(sizeof(int)*(n));
DC->prev=(signed long*)malloc(sizeof(int)*(n));
return;
}
signed long CicDecimate(DVBTCic *DC, signed long in, signed char dump)
{
int i;
DC->nacc[0]+= in;
for(i=0;i<(DC->stages-1);i++)
{
DC->nacc[i+1] += DC->nacc[i];
}
if(dump)
{
DC->diff[0]=DC->nacc[DC->stages-1]-DC->prev[0];
DC->prev[0]=DC->nacc[DC->stages-1];
for(i=1;i<DC->stages;i++)
{ DC->diff[i]= DC->diff[i-1]-DC->prev[i];
DC->prev[i]=DC->diff[i-1];
}
}
return(DC->diff[DC->stages-1]);
}
void ResetDVBTCic(DVBTCic *DC) {
return;
} |