Delete a substring from a string Dry Run in C

Delete a substring from a string is an interactive C dry run visualizer from the String Functions 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.

Delete a substring from a string Program Code

#include <stdio.h>
#include <string.h>

int main() {
    char str[100] = "Hello Beautiful World";
    char substr[] = "Beautiful ";
    int len_sub = strlen(substr);
    
    printf("Original: %s\n", str);
    
    // Find substring
    char *pos = strstr(str, substr);
    
    if(pos != NULL) {
        int index = pos - str;
        int len_str = strlen(str);
        
        // Shift characters left
        for(int i = index; i <= len_str - len_sub; i++) {
            str[i] = str[i + len_sub];
        }
        
        printf("After deletion: %s\n", str);
    } else {
        printf("Substring not found!\n");
    }
    
    return 0;
}

View the complete String Functions programs page.

Program Console Delete a substring from a string Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.