From 8f4662bb05c7e041b609039e9ff60eb2e29d6844 Mon Sep 17 00:00:00 2001 From: margaret-k <60312043+margaret-k@users.noreply.github.com> Date: Mon, 25 May 2020 23:39:41 +0300 Subject: [PATCH] Create dz16.1 --- dz16.1 | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 dz16.1 diff --git a/dz16.1 b/dz16.1 new file mode 100644 index 0000000..d7b8554 --- /dev/null +++ b/dz16.1 @@ -0,0 +1,51 @@ +#include +#include + +struct Toy +{ + char name[100]; + int value; + int age_from; + int age_to; +}; + + +int main() +{ + int max_value = 0; + FILE *fptr; + struct Toy toi; + + if ((fptr = fopen("test.bin","rb")) == NULL) + { + printf("Error! opening file"); + exit(1); + } + + for(int n = 0; n <= 3; ++n) + { + fread(&toi, sizeof(struct Toy), 1, fptr); + // printf("%s\t%d grn\tfrom %d to %d yo\n", toi.name, toi.value, toi.age_from, toi.age_to); + if (max_value < toi.value) + { + max_value = toi.value; + } + } + fclose(fptr); + + printf("most expensive toys:\n"); + + fptr = fopen("test.bin","rb"); + for(int n = 0; n <= 3; ++n) + { + fread(&toi, sizeof(struct Toy), 1, fptr); + if ((max_value - toi.value) <= 50) + { + printf("%s\n", toi.name); + } + } + fclose(fptr); + + + return 0; +}