modified: firmware/main/include/http_client.h
modified: firmware/main/include/lib.h modified: firmware/main/src/http_client.c modified: firmware/main/src/main.c
This commit is contained in:
1 parent
13e6cf1032
commit
e950fcec8f
4 files changed
+68
-41
No files matched your search
@@ -67,4 +67,45 @@ char* floatToString(float num) {
|
||||
return str;
|
||||
}
|
||||
|
||||
// Function to convert an integer to a string
|
||||
char* intToString(int num)
|
||||
{
|
||||
// Allocate memory for the string
|
||||
char* str = (char*)malloc(50 * sizeof(char));
|
||||
|
||||
int i = 0;
|
||||
// Save the sign of the number
|
||||
int sign = num;
|
||||
|
||||
// If the number is negative, make it positive
|
||||
if (num < 0) {
|
||||
num = -num;
|
||||
}
|
||||
|
||||
// Extract digits from the number and add them to the
|
||||
// string
|
||||
do {
|
||||
// Convert integer digit to character
|
||||
str[i++] = num % 10 + '0';
|
||||
} while ((num /= 10) > 0);
|
||||
|
||||
// If the number was negative, add a minus sign to the
|
||||
// string
|
||||
if (sign < 0) {
|
||||
str[i++] = '-';
|
||||
}
|
||||
|
||||
// Null-terminate the string
|
||||
str[i] = '\0';
|
||||
|
||||
// Reverse the string to get the correct order
|
||||
for (int j = 0, k = i - 1; j < k; j++, k--) {
|
||||
char temp = str[j];
|
||||
str[j] = str[k];
|
||||
str[k] = temp;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user