B
biplab
for(i=0;i<256;i++)
{
hist=0;
}
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
k=(long int)rgb1[j];
hist[k]=hist[k]+1;
}
}
for(i=0;i<256;i++)
{
if(hist!=0)
tmp++;
else continue;
}
sum_hist=(int**)malloc(tmp*sizeof(int*));
for(i=0;i<tmp;i++)
sum_hist=(int*)malloc(2*sizeof(int));
for(i=0;i<256;i++)
{
if(hist!=0)
{
//printf("%d %d\n",i,hist);
sum_hist[0]=(int)i;
sum_hist[1]=(int)hist;
printf("%d %d\n",sum_hist[0],sum_hist[1]);
}
else continue;
}
for(i=0;i<tmp;i++)
printf("%d\n",sum_hist[1]);
In the above code segment sum_hist is a double pointer of type long
int...the problem is that when the values of sum_hist is printed withn
the is block..it is giving correct result..but when outside the for
loop..the value is printed......wrong values are printed.....how to
correct the code...
{
hist=0;
}
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
k=(long int)rgb1[j];
hist[k]=hist[k]+1;
}
}
for(i=0;i<256;i++)
{
if(hist!=0)
tmp++;
else continue;
}
sum_hist=(int**)malloc(tmp*sizeof(int*));
for(i=0;i<tmp;i++)
sum_hist=(int*)malloc(2*sizeof(int));
for(i=0;i<256;i++)
{
if(hist!=0)
{
//printf("%d %d\n",i,hist);
sum_hist[0]=(int)i;
sum_hist[1]=(int)hist;
printf("%d %d\n",sum_hist[0],sum_hist[1]);
}
else continue;
}
for(i=0;i<tmp;i++)
printf("%d\n",sum_hist[1]);
In the above code segment sum_hist is a double pointer of type long
int...the problem is that when the values of sum_hist is printed withn
the is block..it is giving correct result..but when outside the for
loop..the value is printed......wrong values are printed.....how to
correct the code...