标签:
int sdsll2str(char *s, long long value) { char *p, aux; unsigned long long v; size_t l; /* Generate the string representation, this method produces * an reversed string. */ v = (value < 0) ? -value : value; p = s; do { *p++ = ‘0‘+(v%10); v /= 10; } while(v); if (value < 0) *p++ = ‘-‘; /* Compute length and add null term. */ l = p-s; *p = ‘\0‘; /* Reverse the string. */ p--; while(s < p) { aux = *s; *s = *p; *p = aux; s++; p--; } return l; } /* Identical sdsll2str(), but for unsigned long long type. */ int sdsull2str(char *s, unsigned long long v) { char *p, aux; size_t l; /* Generate the string representation, this method produces * an reversed string. */ p = s; do { *p++ = ‘0‘+(v%10); v /= 10; } while(v); /* Compute length and add null term. */ l = p-s; *p = ‘\0‘; /* Reverse the string. */ p--; while(s < p) { aux = *s; *s = *p; *p = aux; s++; p--; } return l; }
标签:
原文地址:http://www.cnblogs.com/fangshenghui/p/5700098.html