R16 Remove all occurrences of a character (Recursion) Dry Run in C

R16 Remove all occurrences of a character (Recursion) is an interactive C dry run visualizer from the Recursion programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

R16 Remove all occurrences of a character (Recursion) Program Code

#include <stdio.h>

void removeChar(char str[], char ch, int index, int writeIndex) {
    if(str[index] == '\0') {
        str[writeIndex] = '\0';
        return;
    }

    char currentChar = str[index];

    if(currentChar != ch) {
        str[writeIndex] = currentChar;
        removeChar(str, ch, index+1, writeIndex+1);
    } else {
        removeChar(str, ch, index+1, writeIndex);
    }
}

int main() {
    char text[] = "hello world";
    printf("Original: %s\n", text);
    removeChar(text, 'o', 0, 0);
    printf("After removing 'o': %s\n", text);
    return 0;
}

View the complete Recursion programs page.

Program Console R16 Remove all occurrences of a character (Recursion) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.