Find smallest word in a string Dry Run in C

Find smallest word in 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.

Find smallest word in a string Program Code

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

int main() {
    char str[] = "C programming is an interesting subject";
    char smallest_word[100] = "";
    char current_word[100] = "";
    int min_len = 1000; // Large initial value
    int i = 0, j = 0;
    
    while(str[i] != '\0') {
        // Extract word
        j = 0;
        while(str[i] != ' ' && str[i] != '\0') {
            current_word[j++] = str[i++];
        }
        current_word[j] = '\0';
        
        // Update smallest word
        int len = strlen(current_word);
        if(len < min_len) {
            min_len = len;
            strcpy(smallest_word, current_word);
        }
        
        // Skip spaces
        if(str[i] == ' ') i++;
    }
    
    printf("Smallest word: '%s' (length: %d)\n", smallest_word, min_len);
    return 0;
}

View the complete String Functions programs page.

Program Console Find smallest word in a string Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.