forked from PoliEcho-holding-org/kern
Added atoi() function to string.h header
This commit is contained in:
@@ -18,6 +18,18 @@ char* itoa(uint32_t val, uint8_t base) {
|
|||||||
return &buf[i + 1];
|
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
|
// Some implementations taken from https://en.wikibooks.org/wiki/C_Programming/String_manipulation
|
||||||
char* strcat(char* str1, const char* str2) {
|
char* strcat(char* str1, const char* str2) {
|
||||||
char* s = str1;
|
char* s = str1;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
|
|
||||||
char* itoa(uint32_t val, uint8_t base);
|
char* itoa(uint32_t val, uint8_t base);
|
||||||
|
uint32_t atoi(const char* str);
|
||||||
|
|
||||||
char* strcat(char* str1, const char* str2);
|
char* strcat(char* str1, const char* str2);
|
||||||
char* strchr(const char* str, char c);
|
char* strchr(const char* str, char c);
|
||||||
|
|||||||
Reference in New Issue
Block a user