#include "stdio.h" #include "stdlib.h" #include "string.h" char* c_int_str(int value, int length) { int ndig, dec, sign; char *pstr, *buff, *start; int c; ndig = 0; dec = 2; sign = 0; pstr = fcvt((double) value, ndig, &dec, &sign); if (dec > length) length = dec; if ( (buff=malloc(sizeof(char)*(length+2))) == NULL ) { printf("Not enough memory for the conversion!\n"); start = pstr; } else { start = buff; c = 0; if (strlen(pstr) == 0) { *buff = '0'; buff++; c++; } else { if (value == 0) c = strlen(pstr); } if (sign) { *buff = '-'; buff++; c++; } while (*pstr || c < length-dec) { if (c < length-dec) { *buff = '0'; buff++; c++; } else { *buff = *pstr; buff++; pstr++; c++; } } *buff = '\0'; } return start; }