How to remove the last N characters of a string in C

1 Answer

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

int main(void) {
    char str[] = "C Programming";    
    
    puts(str);
    
    int N = 3;
    str[strlen(str) - N] = '\0';
    
    puts(str);
    
    return 0;
}





/*
run:

C Programming
C Programm

*/

 



answered Sep 27, 2021 by avibootz

Related questions

...