Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,988 questions

51,933 answers

573 users

How to remove the middle character from a string in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
void remove_middle_character_from_string(char s[]) {
    int size = strlen(s);
    int mid = size / 2;
     
    char tmp[256] = "";
     
    strncpy(tmp, s, mid);
    strncpy(tmp + mid, s + mid + 1, size - mid - 1);
     
    tmp[size - 1] = '\0';
     
    strcpy(s, tmp);
}
 
int main() {
    char s1[] = "abcde";
    remove_middle_character_from_string(s1);
    printf("%s\n", s1);
     
    char s2[] = "abcdef";
    remove_middle_character_from_string(s2);
    printf("%s\n", s2);
     
    return 0;
}
  
  
  
  
/*
run:
  
abde
abcef
  
*/

 



answered Mar 15, 2024 by avibootz
edited Jun 12, 2024 by avibootz

Related questions

2 answers 165 views
2 answers 132 views
1 answer 95 views
1 answer 85 views
1 answer 104 views
1 answer 123 views
...