I am little bit confused
Is this a legal way of removing a substring
from a string? What about the second alternative
using strcpy, is it ok even though the source and
dest. strings overlap?
// Remove (first occurence of) sub from src
void func(char *src, char *sub)
{
char *p;
if ((p=strstr(src, sub)) != NULL)
{
memmove(p,p+str len(sub), strlen(p+strlen (sub))+1);
// alternative
// strcpy(p,p+strl en(sub));
}
}
Is this a legal way of removing a substring
from a string? What about the second alternative
using strcpy, is it ok even though the source and
dest. strings overlap?
// Remove (first occurence of) sub from src
void func(char *src, char *sub)
{
char *p;
if ((p=strstr(src, sub)) != NULL)
{
memmove(p,p+str len(sub), strlen(p+strlen (sub))+1);
// alternative
// strcpy(p,p+strl en(sub));
}
}
Comment