Compare commits

..

13 Commits

Author SHA1 Message Date
justuser-31 1d9fdb6847 Исправление наименования 2026-06-11 13:18:12 +03:00
justuser-31 b2f3a84baf Учёт nulTerminator и мелкие исправления 2026-06-11 13:18:12 +03:00
justuser-31 a9a236c9b3 Принудительное перераспределение RAM 2026-06-11 13:18:12 +03:00
justuser-31 a153c6e063 Добавление динамического размера исходя из размера числа 2026-06-11 13:18:12 +03:00
justuser-31 7ce8849e81 Исправление типа double 2026-06-11 13:18:12 +03:00
justuser-31 0555d00bbb Исправление размера максимальной строки 2026-06-11 13:18:12 +03:00
justuser-31 d93d4f863f Конвертация числовых типов в строку 2026-06-11 13:18:12 +03:00
justuser-31 7e0c63f470 Добавление безразмерной строки с динамическим выделением памяти 2026-06-11 13:18:12 +03:00
justuser-31 84b3473665 Исправление возможного двойного включения 2026-06-11 13:18:12 +03:00
justuser-31 f6e460fa82 Убран time.h где он не нужен 2026-06-11 13:18:12 +03:00
justuser-31 2c6371e1d6 Изменение с секунд на миллисекунды (для большей применимости) 2026-06-11 13:18:12 +03:00
justuser-31 faa2df92cc up 2026-06-11 13:18:12 +03:00
justuser-31 f29d07dd1a Initial commit 2026-06-11 13:18:12 +03:00
3 changed files with 81 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
#include <stdio.h>
#include "../libs/string.h"
int main() {
string test = strInit("Hello?");
printf("String now: %s\n", test);
strAdd(&test, " World?");
printf("String now: %s\n", test);
strSet(&test, "Another intresting test with string");
printf("String now: %s\n", test);
free(test);
return 0;
}
+64
View File
@@ -0,0 +1,64 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
// It's base. NUL terminator.
int nulTerm = 1;
// -------------------------------------
// BASE - String and init of this
// -------------------------------------
typedef char* string;
string strInit(char* s) {
string str = malloc(strlen(s) + nulTerm);
strcpy(str, s);
return str;
}
void strResize(string* s, int new_size) {
*s = realloc(*s, new_size + nulTerm);
}
// -------------- END ------------------
// -------------------------------------
// FUNCTION - basic operations
// -------------------------------------
void strAdd(string* s, char* str_new) {
*s = realloc(*s, strlen(*s) + strlen(str_new) + nulTerm);
strcat(*s, str_new);
}
void strSet(string* s, char* str_new) {
*s = realloc(*s, strlen(str_new) + nulTerm);
strcpy(*s, str_new);
}
void strCopy(string* dst, string* src) {
strcpy(*dst, *src);
}
// -------------- END ------------------
// -------------------------------------
// CONVERT - different convert to str
// -------------------------------------
int numLen(double num) {
return snprintf(NULL, 0, "%lf", num);
}
char* int2Str(int* num) {
char* buffer = malloc(numLen(*num) + nulTerm);
sprintf(buffer, "%d", *num);
return buffer;
}
char* float2Str(float* num) {
char* buffer = malloc(numLen(*num) + nulTerm);
sprintf(buffer, "%f", *num);
return buffer;
}
char* double2Str(double* num) {
char* buffer = malloc(numLen(*num) + nulTerm);
sprintf(buffer, "%lf", *num);
return buffer;
}
// -------------- END ------------------
+2
View File
@@ -1,3 +1,5 @@
#pragma once
#ifdef _WIN32
#include <windows.h>
#else