/* * Author : Amit Dutta * Date : 08 Feb 2026 * Repo : https://github.com/notamitgamer/bsc * License : MIT License (See the LICENSE file for details) */ /* Read 'blood donors' file (Name, Address, Age, Blood Type). Print donors with Age < 25 and Blood Type 2. */ /* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(g) */ /* This file is auto-generated by a bot. */ /* This code is not compiled; it is for reference only. */ #include #include #include #include struct donor { char name[21]; // 20 cols + null char address[41]; // 40 cols + null int age; // 2 cols -> int int blood_type; // 1 col -> int }; void create_donor_file(); int main() { FILE *fp; struct donor d; create_donor_file(); fp = fopen("donors.dat", "rb"); if (!fp) { printf("File error.\n"); exit(1); } printf("--- Donors (Age < 25, Type 2) ---\n"); while (fread(&d, sizeof(struct donor), 1, fp) == 1) { if (d.age < 25 && d.blood_type == 2) { printf("Name: %s | Age: %d | Addr: %s\n", d.name, d.age, d.address); } } fclose(fp); return 0; } void create_donor_file() { struct donor data[] = { {"Amit", "Delhi", 22, 2}, // Match {"Rahul", "Mumbai", 30, 2}, // Old {"Sumit", "Pune", 21, 1}, // Wrong type {"Priya", "Goa", 24, 2} // Match }; FILE *f = fopen("donors.dat", "wb"); fwrite(data, sizeof(struct donor), 4, f); fclose(f); }