R19 Remove consecutive duplicate characters Dry Run in C

R19 Remove consecutive duplicate characters 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.

R19 Remove consecutive duplicate characters Program Code

#include <stdio.h>

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

    char currentChar = str[index];
    char previousChar = (index == 0) ? '\0' : str[index - 1];

    if(index == 0 || currentChar != previousChar) {
        str[writeIndex] = currentChar;
        removeConsecutiveDuplicates(str, index+1, writeIndex+1);
    } else {
        removeConsecutiveDuplicates(str, index+1, writeIndex);
    }
}

int main() {
    char text[] = "aabbccddeeff";
    printf("Original: %s\n", text);
    removeConsecutiveDuplicates(text, 0, 0);
    printf("After removal: %s\n", text);
    return 0;
}

View the complete Recursion programs page.

Program Console R19 Remove consecutive duplicate characters Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.