Created
August 10, 2017 18:28
-
-
Save pta2002/15fdf6845bb894921a0ca7d69c04264f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
int number = 30; | |
int cur_char = 0; | |
int size = sizeof(char); | |
char* string = (char*)malloc(size); | |
do { | |
if (cur_char >= size) { | |
size += sizeof(char); | |
string = (char*)realloc(string, size); | |
} | |
string[cur_char] = '0' + (char) number % 10; | |
number /= 10; | |
cur_char++; | |
} while (number > 0); | |
printf("%s\n", string); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment