diff --git a/src/conversionOfNumbers/conversionOfNumbers.c b/src/conversionOfNumbers/conversionOfNumbers.c index 64dae01..b7ae51b 100644 --- a/src/conversionOfNumbers/conversionOfNumbers.c +++ b/src/conversionOfNumbers/conversionOfNumbers.c @@ -6,14 +6,13 @@ char* convertIntToBinaryStr(int input){ int length = 2; int rest; char* result = (char*)malloc(sizeof(char) * length + 1); - int index = length - 1; + result[length] = '\0'; do{ rest = input % 2; input /= 2; - if(rest == 1) result[index] = '1'; - if(rest == 0) result[index] = '0'; - index--; + if(rest == 1) result[length - 1] = '1'; + if(rest == 0) result[length - 1] = '0'; + length--; }while(input != 0); - result[length] = '\0'; return result; } \ No newline at end of file