Search record using function Dry Run in C

Search record using function 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.

Search record using function Program Code

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

struct Employee {
    int id;
    char name[50];
    char dept[30];
};

int searchById(struct Employee arr[], int size, int targetId) {
    for(int i = 0; i < size; i++) {
        if(arr[i].id == targetId) {
            return i;
        }
    }
    return -1;
}

int searchByName(struct Employee arr[], int size, char targetName[]) {
    for(int i = 0; i < size; i++) {
        if(strcmp(arr[i].name, targetName) == 0) {
            return i;
        }
    }
    return -1;
}

int main() {
    struct Employee employees[4] = {
        {101, "John Smith", "IT"},
        {102, "Jane Doe", "HR"},
        {103, "Mike Brown", "Finance"},
        {104, "Lisa Wong", "Marketing"}
    };
    
    int pos = searchById(employees, 4, 103);
    if(pos != -1)
        printf("Found: %s (ID: %d, Dept: %s)\n", 
               employees[pos].name, employees[pos].id, employees[pos].dept);
    else
        printf("Employee not found!\n");
    
    pos = searchByName(employees, 4, "Jane Doe");
    if(pos != -1)
        printf("Found: %s (ID: %d, Dept: %s)\n", 
               employees[pos].name, employees[pos].id, employees[pos].dept);
    else
        printf("Employee not found!\n");
    return 0;
}

View the complete Struct Functions Pointers programs page.

Program Console Search record using function Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.