diff --git a/libs/string.h b/libs/string.h index dde6c47..bd24e24 100644 --- a/libs/string.h +++ b/libs/string.h @@ -1,12 +1,23 @@ #include #include +#include +// ------------------------------------- +// BASE - String and init of this +// ------------------------------------- typedef char* string; string strInit(char* s) { string str = malloc(strlen(s) * sizeof(char)); strcpy(str, s); return str; } +// -------------- END ------------------ + + + +// ------------------------------------- +// FUNCTION - basic operations +// ------------------------------------- void strAdd(string* s, char* str_new) { *s = realloc(*s, strlen(*s) + strlen(str_new)*sizeof(char)); strcat(*s, str_new); @@ -18,3 +29,26 @@ void strSet(string* s, char* str_new) { void strCopy(string* s1, string* s2) { strcpy(*s2, *s1); } +// -------------- END ------------------ + + + +// ------------------------------------- +// CONVERT - different convert to str +// ------------------------------------- +char* int2Str(int* num) { + char* buffer = malloc(12); + sprintf(buffer, "%d", *num); + return buffer; +} +char* float2Str(float* num) { + char* buffer = malloc(12); + sprintf(buffer, "%f", *num); + return buffer; +} +char* double2Str(double* num) { + char* buffer = malloc(12); + sprintf(buffer, "%f", *num); + return buffer; +} +// -------------- END ------------------