From c770ddce02cc61203b0f362ad3a70c2dc9872c56 Mon Sep 17 00:00:00 2001 From: margaret-k <60312043+margaret-k@users.noreply.github.com> Date: Mon, 25 May 2020 23:40:29 +0300 Subject: [PATCH] Create dz16.2 --- dz16.2 | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 dz16.2 diff --git a/dz16.2 b/dz16.2 new file mode 100644 index 0000000..3b43b8b --- /dev/null +++ b/dz16.2 @@ -0,0 +1,52 @@ +include +#include + +struct Toy +{ + char name[100]; + int value; + int age_from; + int age_to; +}; + + +int main() +{ + int n; + int aim_age = 3; + int toys_count = 4; + + FILE *fptr; + struct Toy tois[toys_count]; + + if ((fptr = fopen("test.bin","rb")) == NULL) + { + printf("Error! opening file"); + exit(1); + } + + for(n = 0; n < toys_count; ++n) + { + fread(&tois[n], sizeof(struct Toy), 1, fptr); + } + + fclose(fptr); + + for (int i = 0; i <= toys_count; i++) + { + for (int j = 0; j <= toys_count; j ++) + { + if (i != j) + { + if (((tois[i].value + tois[j].value) <= 20) && + (tois[i].age_from <= aim_age) && ((tois[j].age_from <= aim_age)) && + (tois[i].age_to >= aim_age) && (tois[j].age_to >= aim_age)) + { + printf("%s and %s are good for you\n", tois[i].name, tois[j].name); + } + } + } + } + + return 0; +}