OSDN Git Service

Initial release for VER0.1.5
[lib1stclass/main.git] / itoa.c
1 /*
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright: 2010- 1stclass.co.jp.  All rights reserved.
5 *
6 * Created by Hajime Kurita
7 */
8 #include <string.h>
9
10 #ifdef __cplusplus
11 #include "1stclass.hpp"
12 int firstclass::itoa(int n, char s[]){
13 #else
14 #include "1stclass.h"
15 int itoa(int n, char s[]){
16 #endif
17   int i, sign;
18   if ((sign = n) < 0)
19     n = -n;
20   i = 0;
21   do { // generate digits in reverse order
22     s[i++] = n % 10 + '0'; // get next digit
23   } while ((n /= 10) > 0); // delete it
24   if (sign < 0)
25     s[i++] = '-';
26   s[i] = '\0';
27   reverse_char(s);
28   return 0;
29 }