Access structure members dynamically Dry Run in C

Access structure members dynamically is an interactive C dry run visualizer from the Struct Functions Pointers 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.

Access structure members dynamically Program Code

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

struct Configuration {
    char settingName[50];
    int intValue;
    float floatValue;
    char stringValue[100];
};

void setConfigValue(struct Configuration *config, const char *member, void *value) {
    if(strcmp(member, "intValue") == 0) {
        config->intValue = *(int*)value;
    }
    else if(strcmp(member, "floatValue") == 0) {
        config->floatValue = *(float*)value;
    }
    else if(strcmp(member, "stringValue") == 0) {
        strcpy(config->stringValue, (char*)value);
    }
    else if(strcmp(member, "settingName") == 0) {
        strcpy(config->settingName, (char*)value);
    }
}

void displayConfig(struct Configuration *config) {
    printf("\n--- Configuration ---\n");
    printf("Setting: %s\n", config->settingName);
    printf("Integer: %d\n", config->intValue);
    printf("Float: %.2f\n", config->floatValue);
    printf("String: %s\n", config->stringValue);
}

int main() {
    struct Configuration *config = (struct Configuration*)malloc(sizeof(struct Configuration));
    
    if(config != NULL) {
        setConfigValue(config, "settingName", "User Preferences");
        setConfigValue(config, "intValue", &(int){100});
        setConfigValue(config, "floatValue", &(float){99.99});
        setConfigValue(config, "stringValue", "Dynamic Access Example");
        
        displayConfig(config);
        free(config);
    }
    
    return 0;
}

View the complete Struct Functions Pointers programs page.

Program Console Access structure members dynamically Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.