How to remove a character from a string in C

1 Answer

0 votes
#include <stdio.h>
 
void remove_all_ch_from_s(char s[], int ch);
  
  
int main(void)
{
    char s[] = "the new c ide";
 
    remove_all_ch_from_s(s, 'e');
    puts(s);
    
    return 0;
}
 
void remove_all_ch_from_s(char s[], int ch) 
{ 
    int i, j; 
      
    for (i = j = 0; s[i] != '\0'; i++) 
         if (s[i] != ch) 
             s[j++] = s[i]; 
      
    s[j] = '\0'; 
} 
  

/*
   
run:
   
th nw c id


*/

 



answered Nov 10, 2015 by avibootz

Related questions

1 answer 133 views
1 answer 86 views
1 answer 175 views
1 answer 132 views
2 answers 247 views
1 answer 140 views
1 answer 157 views
...