Created
January 2, 2012 08:41
-
-
Save pasberth/1549905 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <string.h> | |
#include <math.h> | |
void int2str(long, char *); | |
int main(int argc, char *argv[]) | |
{ | |
long i = 12345; | |
char str[] = "00000\0"; | |
int2str(i, str); | |
puts(str); | |
return 0; | |
} | |
void int2str(long n, char *str) | |
{ | |
int len = strlen(str); | |
int i; | |
for( i = 0; i < len; i++ ) | |
{ | |
long mask = pow(10, i+1); | |
int a = (n % mask) / pow(10, i); | |
char c = (char)(a + (unsigned short)'0'); | |
str[len-i-1] = c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment