add: strshift and lst_clear

This commit is contained in:
starnakin 2023-06-28 17:28:20 +02:00
parent 6b07016f94
commit 776bb7dce2
4 changed files with 22 additions and 3 deletions

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include <stdlib.h>
typedef struct s_lst typedef struct s_lst
{ {

16
src/lst/lst_clear.c Normal file
View File

@ -0,0 +1,16 @@
#include "./lst.h"
void lst_clear(lst **root, void (*del)(void *))
{
lst* current = *root;
lst* next;
while (current != NULL)
{
next = current->next;
(*del)(current->content);
free(current);
current = next;
}
free(root);
}

View File

@ -6,7 +6,7 @@ void lst_iter(lst** root, void (*f)(void *))
while (current != NULL) while (current != NULL)
{ {
(*f)(current); (*f)(current->content);
current = current->next; current = current->next;
} }
} }

View File

@ -2,8 +2,10 @@
void str_shift(char *str, int shift) void str_shift(char *str, int shift)
{ {
for (size_t i = 0; str[i] == '\0'; i++) size_t i = 0;
while (str[i - shift - 1] != '\0')
{ {
str[i] = str[i - shift];
i++;
} }
} }