Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #define ERROR_FILE_OPEN -1
- int i = 0;
- struct scan_info{
- char model[25]; // наименование модели
- int price; // цена
- double x_size; // горизонтальный размер области сканирования
- double y_size; // вертикальный размер области сканирования
- int optr; // оптическое разрешение
- int grey; // число градаций серого
- };
- void output_bin(long N, struct scan_info *task_struct)
- {
- FILE *f_output = NULL;
- f_output = fopen("task.bin", "rb");
- if (f_output == NULL){
- printf("Error opening file");
- getch();
- exit(ERROR_FILE_OPEN);
- }
- fseek(f_output, 0, SEEK_SET);
- fread(&N, sizeof(long), 1, f_output);
- fseek(f_output, 4, SEEK_SET);
- printf("nЧитаем структуру из бианрного файлаn");
- printf("Число записей: ");
- printf("%i",N);
- for(i = 0; i < N; i++){
- fread(&task_struct[i], sizeof(struct scan_info), 1, f_output);
- printf("%sn",task_struct[i]);
- }
- fclose(f_output);
- }
- void input_bin(long N, struct scan_info *task_struct)
- {
- FILE *f_input = NULL;
- f_input = fopen("task.bin", "w+b");
- if (f_input == NULL){
- printf("Error opening file");
- getch();
- exit(ERROR_FILE_OPEN);
- }
- fseek(f_input, 0, SEEK_SET);
- fwrite(&N, sizeof(long), 1, f_input);
- fseek(f_input, 4, SEEK_SET);
- for (i=0; i<N; i++){
- if (task_struct[i].price >= 200){
- fwrite(&task_struct[i], sizeof(struct scan_info), 1, f_input);
- }
- }
- fclose(f_input);
- }
- void printf_struct(long N, struct scan_info *task_struct)
- {
- printf("nПолученная структураn");
- for(i = 0; i < N; i++){
- printf("nНазвание: ");
- printf("%sn",task_struct[i].model);
- printf("Цена: ");
- printf("%in",task_struct[i].price);
- printf("Горизонтальный размер области сканирования: ");
- printf("%dn",task_struct[i].x_size);
- printf("Вертикальный размер области сканирования: ");
- printf("%dn",task_struct[i].y_size);
- printf("Оптическое разрешение: ");
- printf("%in",task_struct[i].optr);
- printf("Число градаций серого: ");
- printf("%in",task_struct[i].grey);
- }
- }
- void scanf_struct(long N, struct scan_info *task_struct)
- {
- for(i = 0; i < N; i++){
- printf("nНазвание: ");
- scanf("%s",&task_struct[i].model);
- printf("Цена: ");
- scanf("%i",&task_struct[i].price);
- printf("Горизонтальный размер области сканирования: ");
- scanf("%d",&task_struct[i].x_size);
- printf("Вертикальный размер области сканирования: ");
- scanf("%d",&task_struct[i].y_size);
- printf("Оптическое разрешение: ");
- scanf("%i",&task_struct[i].optr);
- printf("Число градаций серого: ");
- scanf("%i",&task_struct[i].grey);
- }
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- long N;
- struct scan_info *task_struct;
- printf("Введите количество записей о сканерах: ");
- scanf("%i", &N);
- task_struct = (struct scan_info*)malloc(N*sizeof(struct scan_info));
- scanf_struct(N, task_struct);
- printf_struct(N, task_struct);
- input_bin(N, task_struct);
- output_bin(N, task_struct);
- return 0;
- }
- printf("%sn",task_struct[i]);
- fwrite(&N, sizeof(long), 1, f_input);
- //fseek(f_input, 4, SEEK_SET);
- for (i=0; i<N; i++){
- if (task_struct[i].price >= 200){
- fwrite(&task_struct[i], sizeof(struct scan_info), 1, f_input);
- }
- }
Add Comment
Please, Sign In to add comment