Search
 
SCRIPT & CODE EXAMPLE
 

C

remove every appearance of char without malloc in c


void remove_char(char s[], char ch){

    unsigned int strLen = strlen(s);

    // Place ' ' where ch appears
    unsigned int cnt_ch =0 , temp=0;
    int j=0;
    while ( j < strLen ){
        if( s[j] == ch ){
            cnt_ch ++; temp ++; // count number of ch, temp will count if there is more than ch followed by
            // if another char appeared != ch
        }else if ( temp > 0 && s[j] != ch ){

            // assign the current index value to k
            int k = j;

            while ( temp -- ) k --; // reduce k by the number of the appearance of ch

            temp = cnt_ch; // assign back temp = cnt_ch

            s[k] = s[j]; // assign the value of current char to s[k] where ch appears
            s[j] = ' '; // place ' ' instead of the current char
        }
        j++;
    }
    s[strLen - cnt_ch ] ='';

    for(char * c= s; *c; c++){
        printf("%c", *c);
    }


}
Comment

PREVIOUS NEXT
Code Example
C :: int main() { int sum =0; FILE * ptr; ptr = fopen("d:students. "," "); if (ptr ==NULL){ ("file does not exist!!"); exit(0); } 
C :: sum of fibonacci series in c 
C :: buble sort in c that ask user input 
C :: georgia institute of technology 
C :: C Change Value of Array elements 
C :: man write c 
C :: link a lib iusing pragma 
C :: python to java translator online 
C :: which one is faster loop or recursive function? 
C :: how to compress a file in c 
C :: fina students name by using html backend database 
C :: what the value in array not initialized yet c 
C :: c michael 
C :: maximum, minimum, mean, and median of the data set. in array c programming 
C :: golang inline function definition 
C :: #include <stdio.h int main() { int x = 10, *y, **z; y = &x; z = &y; printf(""%d %d %d"", *y, **z, *(*z)); return 0; } 
C :: C Relationship Between Arrays and Pointers 
C :: navigate to line intellij 
C :: gcc comand for running hello.c 
C :: array of pointers to functions 
C :: pre and post increment in c 
Dart :: flutter listtile shape 
Dart :: flutter get current date 
Dart :: round container flutter 
Dart :: flutter card border radius overflow hidden 
Dart :: dart repeat function 
Dart :: flutter scroll to bottom 
Dart :: how to pop all screens flutter 
Dart :: flutter use png as icon 
Dart :: flutter popupmenubutton 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =