Program Console Vignaankosh.com
Execution Panel
Console is empty.
Count occurrences of a substring 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.
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "ababcababcab";
char substr[] = "ab";
int count = 0;
int len_str = strlen(str);
int len_sub = strlen(substr);
int i, j, match;
printf("String: %s\n", str);
printf("Substring: %s\n", substr);
for(i = 0; i <= len_str - len_sub; i++) {
match = 1;
for(j = 0; j < len_sub; j++) {
if(str[i + j] != substr[j]) {
match = 0;
break;
}
}
if(match) {
count++;
i += len_sub - 1; // Skip overlapping (optional)
}
}
printf("Occurrences: %d\n", count);
return 0;
}