Home > Back-end >  C language to read and write files
C language to read and write files

Time:12-04

I try to d array every integer can be converted to a binary number and deposit the sum array, but found the result of an array of the sum is not correct, when I use printf validation d array, found that the two position d array are different, even I want to ask next everybody, where is the problem of the code
 
Int tobit (int b)
{
Static int a [100];
Int I, j, c=0;
for(j=0; j<100; J++)
{
A [j]=0;
}
While (b!=0)
{
I=% 2 b;
A [c]=I;
C + +;
B=b/2;
}
return a;
}

Int main ()
{
Int nb_output=16;
Int sum_size=5;
Int sum [nb_output] [sum_size];
Int d [nb_input];
Int e;
for(i=0; i{
Printf (" % d ", d [I]);
}
printf("\n");

For (int I=0; i{
E=d [I];
Printf (" % d ", d [I]);
Int * pr=tobit (e);
For (int q=sum_size; Q> 0; Q -)
{
The sum [I] [sum_size - q]=pr [q - 1);
}
}
printf("\n");
}

Before and after the first two listed as 2 d array

CodePudding user response:

Why are two output d [I] is not the same?

CodePudding user response:

, 1 d array length for nb_input, and cycle of use value for nb_output, please check if the same two Numbers,
2, array uninitialized, cannot be directly output, please pay attention to whether there is the initialization statement,

CodePudding user response:

Thank you, array length is wrong
  • Related