Find largest word in a string Dry Run in C

Find largest 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 largest word in a string Program Code

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

int main() {
    char str[] = "C programming is an interesting subject";
    char largest_word[100] = "";
    char current_word[100] = "";
    int max_len = 0;
    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 largest word
        if(strlen(current_word) > max_len) {
            max_len = strlen(current_word);
            strcpy(largest_word, current_word);
        }
        
        // Skip spaces
        if(str[i] == ' ') i++;
    }
    
    printf("Largest word: '%s' (length: %d)\n", largest_word, max_len);
    return 0;
}

View the complete String Functions programs page.

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