luc080.c (1547B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 08 Feb 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Automobile engine parts (Serial AA0-FF9, Year, Material, Qty). Retrieve parts between serial numbers BB1 and CC6. 9 */ 10 /* Let Us C, Chap- 17 (Structures), Qn No.: B(c) */ 11 12 /* This file is auto-generated by a bot. */ 13 /* This code is not compiled; it is for reference only. */ 14 15 16 #include <stdio.h> 17 #include <string.h> 18 #include <stdlib.h> 19 20 struct part 21 { 22 char serial[4]; // 3 chars + null terminator 23 int mfg_year; 24 char material[20]; 25 int quantity; 26 }; 27 28 void retrieve_parts(struct part *p, int n); 29 30 int main() 31 { 32 struct part inventory[] = { 33 {"AA0", 2020, "Steel", 50}, 34 {"BB2", 2021, "Aluminum", 20}, 35 {"BB5", 2022, "Carbon", 10}, 36 {"CC1", 2021, "Steel", 100}, 37 {"CC7", 2023, "Titanium", 5}, 38 {"FF9", 2024, "Iron", 60} 39 }; 40 int n = 6; 41 42 printf("--- Parts with Serial Numbers between BB1 and CC6 ---\n"); 43 retrieve_parts(inventory, n); 44 45 return 0; 46 } 47 48 void retrieve_parts(struct part *p, int n) 49 { 50 int i; 51 // We compare strings lexicographically 52 char start[] = "BB1"; 53 char end[] = "CC6"; 54 55 for (i = 0; i < n; i++) 56 { 57 if (strcmp(p[i].serial, start) >= 0 && strcmp(p[i].serial, end) <= 0) 58 { 59 printf("Serial: %s | Year: %d | Mat: %s | Qty: %d\n", 60 p[i].serial, p[i].mfg_year, p[i].material, p[i].quantity); 61 } 62 } 63 }