I'm writing a code to convert a text into ASCII and then to binary. The text->ASCII conversion works fine, but during the ASCII->binary conversion I get an infinite loop when I run the program. Which part of my code is wrong?
P. S. I'm working with the cs50 library provided by the Harvard CS50 course, hence the fourth line.
const int BITS_IN_BYTE = 8;
int main(void)
{
string text = get_string("Text: ");
int binary[BITS_IN_BYTE];
for (int i=0, len = strlen(text); i<len; i++)
{
int ascii = text[i];
printf("%d\n", ascii);
for(i=0; ascii>0; i++)
{
ascii = ascii / 2;
binary[i] = ascii % 2;
}
printf("Binary for the given number is: ");
for(i=i-1; i>=0; i--)
{
printf("%d", binary[i]);
}
}
}