Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions dz16.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
include <stdio.h>
#include <stdlib.h>

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;
}