How to remove the first 3 characters from a string in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
#include <assert.h>

void removeFirstN(char* str, size_t N) {
    assert(N != 0 && str != 0);
    size_t len = strlen(str);
    if (N > len)
        return;  
    memmove(str, str + N, len - N + 1);
}

int main(void) {
    char str[] = "c programming";
    
    int N = 3;
    
    removeFirstN(str, N);

    puts(str);

    return 0;
}




/*
run:

rogramming

*/

 



answered Jun 13, 2022 by avibootz

Related questions

1 answer 114 views
1 answer 127 views
1 answer 108 views
1 answer 118 views
1 answer 118 views
...