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 114 views
1 answer 115 views
1 answer 163 views
1 answer 151 views
1 answer 111 views
1 answer 143 views
...