int main(){
int n,i=0,c1,c2;
char a[1000];
scanf("%d",&n);
while(n!=0)
{
a[i]=n%2;
printf("%d",a[i]); // This prints Values Correctly
n=n/2;
i++;
}
a[i]='\0';
for(i=0;a[i]!='\0';i++)
printf("%d",a[i]); //This prints only the first element of the array
}
What am I missing here? Why can't I loop through and print the values of the char array although it works when I try to print it inside while loop?

a[i]!='\0'isa[i] != 0int countBit = i;) theni < countBit(for(i=0;i < countBit;i++)