The problem is only in the last scanf of the program
The following program works perfectly the 1st time, but as soon as I use the again (from the restart/quit goto program in the last), the whole program just starts to run infinitely without even stopping for the rightly written scanf() commands. NOTE that in the given program, BinToDec and dgts functions that are working perfectly.
int main()
{
printf("WELCOME TO THIS AMAZING BINARY TO DECIMAL NUMBER CONVERTER\n");
start:;
int bin, dgt, rev;
printf("\nEner the binary number to convert it into decimal number: ");
scanf("%d", &bin);
printf("\n\nYour binary number = %d\n", bin);
int nib = bin;
dgt = dgts(bin);
char str[dgt + 1];
sprintf(str, "%d", bin);
int dec = BinToDec(dgt, str);
printf("\n\n* * * * * * *\ndecimal no. is: %d\n* * * * * * *\n\n", dec);
char qor;
printf("If you want to quit, enter q;\n If you want to use this tool again, enter any other character");
scanf("\t% c", &qor);
if (qor == 'q')
{
goto end;
}
else
{
goto start;
}
end:
return 0;
}
Ps: I do know the problem, and I've fixed it in my final code, but I wanted to know the reason of how just a single space in between the format specfier is leading to that weir result.