I am with a project to recreate C functions to learn and I am with the memset function which when trying to recreate its operation gives me the following error
*** stack smashing detected ***: <unknown> terminated
[1] 3679 abort (core dumped) ./a.out
This is the code and my main
#include <stdio.h>
void *ft_memset(void *str, int c, size_t n)
{
char *ptr;
ptr = str;
while (n)
{
*(ptr++) = (unsigned char)c;
n--;
}
return (str);
}
int main()
{
char str[] = "";
ft_memset(str, 4, 10);
printf("%s", str);
}