Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* convertFromDecimal(int num, int toBase) {
- char chars[] = { "0123456789ABCDEFGHIJ" };
- char *result;
- char digit[] = { '', '' };
- char temp[RESERVE_CHARS];
- memset(temp, 0, sizeof temp);
- result = (char*)calloc(RESERVE_CHARS, sizeof(char));
- memset(result, 0, sizeof result);
- int over;
- while (num > 0) {
- over = num % toBase;
- digit[0] = chars[over];
- strcat(temp, digit);
- num /= toBase;
- }
- /* reverse the temp string to get real digit */
- int p, x;
- for ( p = strlen(temp)-1, x=0; p >= 0; --p, ++x) {
- result[x] = temp[p];
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement