This already exists in the C++ standard library (std::rotate), and the C standard library (memmove)
If you're using C++, (since it comes with a std::swap function, and C can't swap with parameters like that):
void remove(int index, char *arr, int len)
{
if (len<=0)
len = strlen(arr);
std::rotate(arr+index, arr+index+1, arr+len);
arr[len-1] = NULL;
}
Also, in C++, use a std::vector or std::string rather than a naked char* pointer.
If you're using C:
void remove(int index, char *arr, int len)
{
if (len<=0)
len = strlen(arr);
memmove(arr+index, arr+index+1, len-index-1);
arr[len-1] = NULL;
}
If you are using naked char* pointers, always pass a length.
swap? Is it C or C++?swapis standard inC++(after ausing namespace std), but it could also be aCfunction. Hard to tell.