Added atoi() function to string.h header

This commit is contained in:
2024-04-11 13:12:13 +02:00
parent 5da2476852
commit 3441b31900
2 changed files with 13 additions and 0 deletions
+12
View File
@@ -18,6 +18,18 @@ char* itoa(uint32_t val, uint8_t base) {
return &buf[i + 1];
}
uint32_t atoi(const char* str) {
uint32_t res = 0;
// TODO: Add error checking
while (*str >= '0' && *str <= '9') {
res = res * 10 + (*str++ - '0');
}
return res;
}
// Some implementations taken from https://en.wikibooks.org/wiki/C_Programming/String_manipulation
char* strcat(char* str1, const char* str2) {
char* s = str1;
+1
View File
@@ -4,6 +4,7 @@
#include "stdint.h"
char* itoa(uint32_t val, uint8_t base);
uint32_t atoi(const char* str);
char* strcat(char* str1, const char* str2);
char* strchr(const char* str, char c);