|
@ -0,0 +1,24 @@ |
|
|
|
|
|
#include "StringManipulation.h" |
|
|
|
|
|
/*Code written by Julius Philipp Engel, fdai7057*/ |
|
|
|
|
|
char *to_string(int number) |
|
|
|
|
|
{ |
|
|
|
|
|
if(number==0) |
|
|
|
|
|
{ |
|
|
|
|
|
return "0\0"; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
int cpy = number, len = 0; |
|
|
|
|
|
while(number>0){ |
|
|
|
|
|
++len; |
|
|
|
|
|
number /= 10; |
|
|
|
|
|
} |
|
|
|
|
|
char *str = calloc(len+1, sizeof(char)); |
|
|
|
|
|
for(int i=0,j=len-1;i<len;++i,--j){ |
|
|
|
|
|
*(str+j) = '0' + (cpy % 10); |
|
|
|
|
|
cpy /= 10; |
|
|
|
|
|
} |
|
|
|
|
|
*(str+len) = '\0'; |
|
|
|
|
|
return str; |
|
|
|
|
|
} |
|
|
|
|
|
} |