-
Notifications
You must be signed in to change notification settings - Fork 0
/
itoa.c
62 lines (56 loc) · 996 Bytes
/
itoa.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MAX_INT_RANGE 4294967296
void itoa(int, int, char*);
void reverse_order(char*, int);
void itoa(int number, int base, char *destination)
{
int temp2=0, counter=0;
char temp1=0;
do
{
temp1 = number%base;
destination[counter] = temp1+48;
temp2 = number/base;
number = temp2;
counter++;
}
while(temp2!=0);
destination[counter]='\0';
reverse_order(destination, strlen(destination));
}
void reverse_order(char *string, int length)
{
int i = 0, counter1, counter2;
counter1 = 0;
counter2 = length-1;
char temp1;
while(counter1 < counter2)
{
temp1 = string[counter1];
string[counter1] = string[counter2];
string[counter2] = temp1;
counter1++;
counter2--;
}
}
void main()
{
char buffer[15]="";
int counter = 0;
while (1)
{
itoa(counter, 10, buffer);
strcat(buffer, "\r\n\0");
if (counter == MAX_INT_RANGE)
{
counter = 0;
}
else
{
counter++;
}
printf("%s",buffer);
}
}