0

hi guys, first time posting here :cheesy: i have problems with my assignment..

Here is a piece of code inside my main function, I have to convert decimal number to binary. I take decimal numbers divide by 2, and strcat() the remaining, then use a function strrev() to reverse it to get the correct output. The output is correct, but the problem is i always got 3 funny characters at the end of my output. I really dont know why, can someone help me out please :sad:

```
int decimal = charToDecimal(c);
char *bin;
do{
if((decimal % 2)==1){
decimal = decimal /2;
bin = strcat(bin,"1");
}else if((decimal % 2)==0){
decimal = decimal /2;
bin = strcat(bin,"0");
}
}while(decimal>0);
printf("Converting decimal to binary. Answer is: %s", strrev(bin));
```