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

Function litoa

stdlib/cpp/iostream.hpp:96–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94 }
95
96 void litoa(long int num, char* str) {
97 int i = 0;
98 int isNegative = 0;
99
100 if (num == 0) {
101 str[i++] = '0';
102 str[i] = '\0';
103 return;
104 }
105
106 if (num < 0) {
107 isNegative = 1;
108 num = -num;
109 }
110
111 while (num != 0) {
112 int rem = num % 10;
113 str[i++] = rem + '0';
114 num = num / 10;
115 }
116
117 if (isNegative)
118 str[i++] = '-';
119
120 str[i] = '\0';
121
122 // Reverse the string
123 int start = 0;
124 int end = i - 1;
125 while (start < end) {
126 char temp = str[start];
127 str[start] = str[end];
128 str[end] = temp;
129 start++;
130 end--;
131 }
132 }
133
134namespace std {
135

Callers 1

ostreamClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected