MCPcopy Create free account
hub / github.com/IntegralPilot/wasm_os / itoa

Function itoa

stdlib/cpp/iostream.hpp:20–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18}
19
20 void itoa(int num, char* str) {
21 int i = 0;
22 int isNegative = 0;
23
24 if (num == 0) {
25 str[i++] = '0';
26 str[i] = '\0';
27 return;
28 }
29
30 if (num < 0) {
31 isNegative = 1;
32 num = -num;
33 }
34
35 while (num != 0) {
36 int rem = num % 10;
37 str[i++] = rem + '0';
38 num = num / 10;
39 }
40
41 if (isNegative)
42 str[i++] = '-';
43
44 str[i] = '\0';
45
46 // Reverse the string
47 int start = 0;
48 int end = i - 1;
49 while (start < end) {
50 char temp = str[start];
51 str[start] = str[end];
52 str[end] = temp;
53 start++;
54 end--;
55 }
56 }
57
58 void llitoa(long long int num, char* str) {
59 int i = 0;

Callers 2

ostreamClass · 0.70
s_ostreamClass · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected