How to remove last two characters from a string in C

1 Answer

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

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




/*
run:

C Programming
C Programmi

*/

 



answered Sep 27, 2021 by avibootz

Related questions

1 answer 98 views
1 answer 106 views
1 answer 150 views
1 answer 134 views
1 answer 96 views
1 answer 132 views
...