Skip to content

Instantly share code, notes, and snippets.

@pta2002
Created August 10, 2017 18:27
Show Gist options
  • Save pta2002/e54b983996536bd9859cd3737a880de1 to your computer and use it in GitHub Desktop.
Save pta2002/e54b983996536bd9859cd3737a880de1 to your computer and use it in GitHub Desktop.
#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