I am not sure of what you are trying to do. However, 1st off *ch = 0; will not set all 5 bytes to 0. I assume you are trying to set all bits in a char to 1 bit by bit. You could of course just assign 0xFF to the char but if it's for an exercise sake then ok. Anyway, I believe the code below is closer to what you are trying to do but I just modified your code so it's still ugly but it works.
Code:
void showbits(unsigned char *n,int b);
int main(void)
{
int i,j;
unsigned char *ch;
ch=malloc(sizeof(unsigned char)*5);
memset(ch,0,sizeof(unsigned char)*5);
for(j=0;j<5;j++) /* Next byte */
{
/* Set 1st bit to 1 */
*(ch+j)=*(ch+j) | 1;
for(i=0;i<7;i++)
{
*(ch+j)=*(ch+j)<<1; /* Shift all bits left 1 */
*(ch+j)=*(ch+j) | 1; /* Reset 1st bit to 1 */
}
}
}
void showbits(unsigned char *n,int b)
{
int i,j,k;
unsigned char mask;
int count=0;
for(j=b-1;j>0;j--)
{
mask = 128;
for(i=7;i>=0;i--)
{
k=*(n+j) & mask>>i;
k==0 ? printf("0"):printf("1");
count++;
}
}
printf("\n%d\n",count);
}