Library system (book records) Dry Run in C

Library system (book records) is an interactive C dry run visualizer from the Structures Arrays 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.

Library system (book records) Program Code

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

struct Book {
    int bookId;
    char title[100];
    char author[50];
    int quantity;
    float price;
};

void displayBooks(struct Book b[], int n) {
    printf("\n%-8s %-35s %-20s %-10s %-10s\n", 
           "Book ID", "Title", "Author", "Qty", "Price");
    for(int i = 0; i < n; i++) {
        printf("%-8d %-35s %-20s %-10d ₹%-9.2f\n", 
               b[i].bookId, b[i].title, b[i].author, 
               b[i].quantity, b[i].price);
    }
}

int searchBook(struct Book b[], int n, int id) {
    for(int i = 0; i < n; i++)
        if(b[i].bookId == id) return i;
    return -1;
}

int main() {
    struct Book library[100];
    int n, choice, id, idx;
    
    printf("Enter number of books: ");
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++) {
        printf("\nBook %d:\n", i+1);
        printf("ID: "); scanf("%d", &library[i].bookId);
        printf("Title: "); scanf(" %[^\n]", library[i].title);
        printf("Author: "); scanf(" %[^\n]", library[i].author);
        printf("Quantity: "); scanf("%d", &library[i].quantity);
        printf("Price: "); scanf("%f", &library[i].price);
    }
    
    do {
        printf("\n===== LIBRARY MENU =====\n");
        printf("1. Display All Books\n");
        printf("2. Search Book by ID\n");
        printf("3. Exit\n");
        printf("Choice: ");
        scanf("%d", &choice);
        
        switch(choice) {
            case 1:
                displayBooks(library, n);
                break;
            case 2:
                printf("Enter Book ID: ");
                scanf("%d", &id);
                idx = searchBook(library, n, id);
                if(idx != -1) {
                    printf("\nBook Found:\n");
                    printf("Title: %s\nAuthor: %s\nQty: %d\nPrice: ₹%.2f\n", 
                           library[idx].title, library[idx].author, 
                           library[idx].quantity, library[idx].price);
                } else {
                    printf("Book not found!\n");
                }
                break;
            case 3:
                printf("Exiting...\n");
                break;
            default:
                printf("Invalid choice!\n");
        }
    } while(choice != 3);
    
    return 0;
}

View the complete Structures Arrays programs page.

Program Console Library system (book records) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.