bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / letusc / luc080.c

luc080.c (1356B)


      1 /* Automobile engine parts (Serial AA0-FF9, Year, Material, Qty). Retrieve parts between serial numbers BB1 and CC6.
      2 */
      3 /* Let Us C, Chap- 17 (Structures), Qn No.: B(c) */
      4 
      5 /* This file is auto-generated by a bot. */
      6 /* This code is not compiled; it is for reference only. */
      7 
      8 
      9 #include <stdio.h>
     10 #include <string.h>
     11 #include <stdlib.h>
     12 
     13 struct part
     14 {
     15     char serial[4]; // 3 chars + null terminator
     16     int mfg_year;
     17     char material[20];
     18     int quantity;
     19 };
     20 
     21 void retrieve_parts(struct part *p, int n);
     22 
     23 int main()
     24 {
     25     struct part inventory[] = {
     26         {"AA0", 2020, "Steel", 50},
     27         {"BB2", 2021, "Aluminum", 20},
     28         {"BB5", 2022, "Carbon", 10},
     29         {"CC1", 2021, "Steel", 100},
     30         {"CC7", 2023, "Titanium", 5},
     31         {"FF9", 2024, "Iron", 60}
     32     };
     33     int n = 6;
     34 
     35     printf("--- Parts with Serial Numbers between BB1 and CC6 ---\n");
     36     retrieve_parts(inventory, n);
     37 
     38     return 0;
     39 }
     40 
     41 void retrieve_parts(struct part *p, int n)
     42 {
     43     int i;
     44     // We compare strings lexicographically
     45     char start[] = "BB1";
     46     char end[] = "CC6";
     47 
     48     for (i = 0; i < n; i++)
     49     {
     50         if (strcmp(p[i].serial, start) >= 0 && strcmp(p[i].serial, end) <= 0)
     51         {
     52             printf("Serial: %s | Year: %d | Mat: %s | Qty: %d\n",
     53                    p[i].serial, p[i].mfg_year, p[i].material, p[i].quantity);
     54         }
     55     }
     56 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror