If you have a pointer to a string, for example:
char *s = "This is my string";
then you can just do s++ .
If you have an array of characters, a pointer to that array might be a better option:
char s[] = "This is my string"; char *ps = s;
then you can do ps++ and make sure you are using ps , not s .
If you do not want to have a separate pointer to your array, you can use memmove to copy data:
memmove (s, s+1, strlen (s+1) + 1);
although none of them will work for an initially empty string, so you need to check this first. Also keep in mind that trying to modify string literals this way (or in any way, really) is not recommended, as it is undefined as to whether it is allowed.
Another solution is just loop code:
for (char *ps = s; *ps != '\0'; ps++) *ps = *(ps+1); *ps = '\0';
This will work for all rows, empty or others.
source share