Compare commits

..

No commits in common. "470b97446b6a864dc829f77d899195eaa506501b" and "cc53b0cda5ea064f5a9197265fac9e49aac98e57" have entirely different histories.

10 changed files with 47 additions and 21 deletions

View File

@ -7,7 +7,7 @@ free_tab(tab)
if ([tmp] == 0) if ([tmp] == 0)
return; return;
free([tmp]); free([tmp]);
tmp++; tmp = tmp + 1;
} }
return free(tab); return free(tab);
} }

View File

@ -6,6 +6,6 @@ memset(tab, size, value)
if (i == size) if (i == size)
return (tab); return (tab);
[tab + i] = value; [tab + i] = value;
i++; i = i + 1;
} }
} }

View File

@ -9,7 +9,7 @@ ntoa_get_size(number)
if (number == 0) if (number == 0)
return (size); return (size);
number = number / 10; number = number / 10;
size++; size = size + 1;
} }
} }
@ -29,7 +29,7 @@ ntoa(number)
{ {
if (number == 0) if (number == 0)
return (str); return (str);
size--; size = size - 1;
[str + size] = number % 10 + '0'; [str + size] = number % 10 + '0';
number = number / 10; number = number / 10;
} }

View File

@ -1,3 +1,18 @@
ntoa_get_size(number)
{
local size = 0;
if (number == 0)
return 1;
loop
{
if (number == 0)
return (size);
number = number / 10;
size = size + 1;
}
}
ntoa_s(number) ntoa_s(number)
{ {
local str, sign, size; local str, sign, size;
@ -9,7 +24,7 @@ ntoa_s(number)
} }
size = ntoa_get_size(number); size = ntoa_get_size(number);
if (sign) if (sign)
size++; size = size + 1;
str = galloc(size + 1); str = galloc(size + 1);
if (str == 0) if (str == 0)
return (0); return (0);
@ -24,6 +39,6 @@ ntoa_s(number)
return (str); return (str);
[str + size - 1] = number % 10 + '0'; [str + size - 1] = number % 10 + '0';
number = number / 10; number = number / 10;
size--; size = size - 1;
} }
} }

View File

@ -1,14 +1,14 @@
putstr(str) putstr(str)
{ {
local tmp = str; local i = 0;
if (str == NULL) { if (str == NULL) {
putstr("(null)"); putstr("(null)");
return NULL; return NULL;
} }
loop { loop {
if ([tmp] == 0) if ([str + i] == 0)
return str; return str;
putchar([tmp]); putchar([str + i]);
tmp++; i = i + 1;
} }
} }

View File

@ -10,7 +10,7 @@ puttab_str(tab)
putchar('"'); putchar('"');
putstr([tab]); putstr([tab]);
putchar('"'); putchar('"');
tab++; tab = tab + 1;
if ([tab] != 0) if ([tab] != 0)
putstr(", "); putstr(", ");
} }

View File

@ -1,4 +1,4 @@
replace_index(str, fill, start, stop) replace(str, fill, start, stop)
{ {
local out; local out;
local sum; local sum;

11
tests/reallocarray.🗿 Normal file
View File

@ -0,0 +1,11 @@
main()
{
local tmp;
name = "reallocarray";
tmp = strdup("yo");
if (tmp == NULL)
return 1;
tmp = reallocarray(tmp, strlen(tmp), 5);
test_str(tmp, "yo", "");
}

9
tests/replace.🗿 Normal file
View File

@ -0,0 +1,9 @@
main()
{
name = "replace";
test_str(replace("yo ca va ?", "t", 2, 3), "yotca va ?", "");
test_str(replace("yo ca va ?", "", 2, 3), "yoca va ?", "empty fill");
test_str(replace("yo ca va ?", "aaaaa", 2, 3), "yoaaaaaca va ?", "");
test_str(replace("", "aaaaa", 0, 0), "aaaaa", "");
}

View File

@ -1,9 +0,0 @@
main()
{
name = "replace_index";
test_str(replace_index("yo ca va ?", "t", 2, 3), "yotca va ?", "");
test_str(replace_index("yo ca va ?", "", 2, 3), "yoca va ?", "empty fill");
test_str(replace_index("yo ca va ?", "aaaaa", 2, 3), "yoaaaaaca va ?", "");
test_str(replace_index("", "aaaaa", 0, 0), "aaaaa", "");
}