How to remove the first and the last character from a string in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
int main(void) {
    char s[] = "C-programming";
     
    puts(s);
 
    strcat(strcpy(s, s + 1), "");
    s[strlen(s) - 1] = '\0';
     
    puts(s);
     
    return 0;
}
 
 
   
/*
run:
   
C-programming
-programmin
 
*/

 



answered Feb 26, 2021 by avibootz

Related questions

...