Let's say I have a string which contains the following text:
#Line1 Hello, today I ate 3 crackers for dinner
#Line2 and 4 crackers with some soup for lunch.
#Line3 For breakfast tomorrow, I plan on eating
#Line4 bacon, eggs, and ham.
and I wanted to cut the part of the string from one substring to another substring, for example from "#Line3"
to \n
to get the following output:
#Line1 Hello, today I ate 3 crackers for dinner
#Line2 and 4 crackers with some soup for lunch.
#Line4 bacon, eggs, and ham.
(Just basically cutting out everything from #Line3
to \n
and in essence removing the entire 3rd line)
I have read that this could be done with the function memmove
but have not been able to figure out how to correctly do so. However, if anyone has a solution that does not involve memmove, of course that would be equally appreciated.
Here's what I have so far:
int str_cut(char *str, char *begin, int len)
{
int l = strlen(str);
if (strlen(begin) + len > l) len = l - begin;
memmove(str + strlen(begin), str + begin + len, l - len + 1);
return len;
}
This is so far pretty far off in accomplishing what I want because it depends on knowing the length of what needs to be cut out and what I want it to do is cut out between 2 chars , to go along with my previous example to cut everything between "line3
" and \n