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)
Difficulty Beginner (index: 3 / 10)

Concepts

Beta Feature

This concept detection system is still in beta and may occasionally show incorrect or incomplete results.

  • Pointers
  • Recursion
  • Array

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);
        }
    }
}

Explanation

Explain with AI

Copy the prompt below and paste it into any AI assistant.

    You are explaining a C programming code to a beginner.

    STRICT RULES:

    - Only use the given code. Do NOT assume anything not present.

    - Do NOT add extra examples.

    - Keep explanation clear and short.

    - If something is unclear, say "Not clear from code".

    - Follow the exact format below. Do NOT change headings.

    FORMAT:

    [START]

    ## What it does

    (Explain the overall purpose in 1-2 sentences)

    ## Step-by-step

    (Explain how the code works in steps, simple language)

    ## Key Concepts

    (List concepts like loop, condition, function, etc.)

    ## Notes

    (Mention any limitations, errors, or assumptions)

    [END]

    CODE (luc080.c):

    #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);
            }
        }
    }