Skip to content

luc080.c

Problem Statement

Automobile engine parts (Serial AA0-FF9, Year, Material, Qty). Retrieve parts between serial numbers BB1 and CC6.

Metadata

Property Detail
Author Amit Dutta amitdutta4255@gmail.com
Date 08 Feb 2026
License MIT License (See the LICENSE file for details)

Actions

Raw View on GitHub

💡 You can print or save this file by opening Raw and using your browser.

Source Code

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

struct part
{
    char serial[4]; // 3 chars + null terminator
    int mfg_year;
    char material[20];
    int quantity;
};

void retrieve_parts(struct part *p, int n);

int main()
{
    struct part inventory[] = {
        {"AA0", 2020, "Steel", 50},
        {"BB2", 2021, "Aluminum", 20},
        {"BB5", 2022, "Carbon", 10},
        {"CC1", 2021, "Steel", 100},
        {"CC7", 2023, "Titanium", 5},
        {"FF9", 2024, "Iron", 60}
    };
    int n = 6;

    printf("--- Parts with Serial Numbers between BB1 and CC6 ---\n");
    retrieve_parts(inventory, n);

    return 0;
}

void retrieve_parts(struct part *p, int n)
{
    int i;
    // We compare strings lexicographically
    char start[] = "BB1";
    char end[] = "CC6";

    for (i = 0; i < n; i++)
    {
        if (strcmp(p[i].serial, start) >= 0 && strcmp(p[i].serial, end) <= 0)
        {
            printf("Serial: %s | Year: %d | Mat: %s | Qty: %d\n",
                   p[i].serial, p[i].mfg_year, p[i].material, p[i].quantity);
        }
    }
}