//#define _CRT_SECURE_NO_WARNINGS #include #include #include struct Film { char name[32]; char Genre[32]; char Producer[32]; double Rating; double Price; }*arr = NULL; int N = 0; void setData() { for (int i = 0; i < N; i++) { printf("\nНазва фільму: "); scanf("%s", &arr[i].name); printf("\nЖанр "); scanf("%s", &arr[i].Genre); printf("\nРежисер "); scanf("%s", &arr[i].Producer); printf("\nРейтинг "); scanf("%lf", &arr[i].Rating); printf("\nЦіна за диск "); scanf("%lf", &arr[i].Price); } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void showData() { system("cls"); for (int i = 0; i < N; i++) { printf("\n============================================="); printf("\n%d \nНазва фільму: %s ", i + 1, arr[i].name); printf("\nЖанр: %s ", arr[i].Genre); printf("\nРежисер: %s ", arr[i].Producer); printf("\nРейтин: %lf ", arr[i].Rating); printf("\nЦiна за диск: %lf $", arr[i].Price); } system("pause"); system("cls"); } void Search() { char Genre[32]; printf("\nВведiть жанр:"); scanf("%s", &Genre); system("cls"); for (int i = 0; i < N; i++) { if (strstr(Genre, arr[i].Genre)) { printf("\n=============================================" ); printf("\n%d \nНазва фільму: %s ",i+1, arr[i].name); printf("\nЖанр: %s ", arr[i].Genre); printf("\nРежисер: %s ", arr[i].Producer); printf("\nРейтин: %lf ", arr[i].Rating); printf("\nЦiна за диск: %lf $", arr[i].Price); } } system("pause"); system("cls"); } void writeStruct(const char* path) { FILE* f = fopen(path, "wb"); for (int i = 0; i < N; i++) fwrite(&arr[i], sizeof(Film), 1, f); fclose(f); } void readStruct(const char* path) { FILE* f; f = fopen(path, "rb"); if (f == NULL) writeStruct(path); else { fseek(f, 0, SEEK_END); N = ftell(f) / sizeof(Film); rewind(f); arr = (Film*)malloc(N * sizeof(Film)); fread(arr, sizeof(Film), N, f); fclose(f); } } int main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); readStruct("d:\\practice.bin"); setData(); showData(); Search(); writeStruct("d:\\practice.bin"); return 0; }