Code:
Function call:
char* converted = ConvertDoubleToStr(666654); printf("Converted string: %s \n", converted); Function:
char* ConvertDoubleToStr(double d) { const int t = sizeof (double); char resultT[t] = " "; //int const dLength = sprintf(resultT, 0, "%lf", d); int const dLength = sprintf(resultT, "%lf", d); if (dLength < 0) return NULL; char *result = (char*)malloc(dLength + 1); if (result == NULL) return NULL; //int const resultLength = sprintf(result, dLength + 1, "%lf", d); int const resultLength = sprintf(result, "%lf", d); if (resultLength < 0) { free(result); return NULL; } printf("Converted string (d->s): %s \n", result); return result; } When exiting the function (by the way, the line printf("Converted string (d->s): %s \n", result); shows the correct result) when assigning the result of the function, I get an error:
Tell me, please, where am I wrong? thank

int const dLength = sprintf(resultT, "%lf", d);? Write in 8 bytes a line much bigger ... - Harry