Advertisement
Underhing

ЯВУ. ЛАБ12. ВЕР 1.0

May 13th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define M 10
  5. #define N 33
  6.  
  7. struct MAGAZIN
  8.     {
  9.         char a[N];
  10.         char name[N];//пункт назначения
  11.         char shop[N];//тип самолета
  12.         unsigned int price;//номер рейса
  13.     };
  14. typedef struct MAGAZIN MAGAZIN;
  15.  
  16.  
  17. int main()
  18. {
  19.     MAGAZIN *x,b;
  20.     FILE *file;
  21.     FILE *fp;
  22.     int p;
  23. const int m=10;
  24.        int i=0,f=0;// limit = 33;
  25.     char limit [N];
  26.     x=(MAGAZIN*)malloc(M*sizeof(MAGAZIN));
  27.  
  28.     file=fopen("MAGAZIN.txt","r");
  29.     printf ("\033[1;33mПРОГРАММА ДЛЯ ПОИСКА ТОВАРА В МАГАЗИНАХ\033[0m\n");
  30.     printf("---{СТРУКТУРА}---\n");
  31.     printf("Магазин: Товар:         Цена:\n");
  32.     while ((fscanf(file,"%s%s%d",x[i].name,x[i].shop,&x[i].price))!= EOF)
  33.     {
  34.         printf("%s\t %s\t%d\n",x[i].name,x[i].shop,x[i].price);
  35.         i++;
  36.     }
  37.     fclose(file);
  38.  
  39.      fp=fopen("MAGAZIN.dat","wb");
  40.     fwrite(&m,sizeof(int),1,fp);
  41.     for(i=0;i<M;i++)
  42.     {
  43.         fwrite(&x[i],sizeof(MAGAZIN),1,fp);
  44.     }
  45.     fclose(fp);
  46.     fp=fopen("MAGAZIN.dat","rb");
  47.     fread(&m,sizeof(int),1,fp);
  48.     scanf("%d",&p);
  49.     fseek(fp,p*sizeof(MAGAZIN),SEEK_CUR);
  50.     fread(&b,sizeof(MAGAZIN),1,fp);
  51.     printf("Информация о самолете:\n%s\t%s\t%u\n",b.name,b.shop,b.price);
  52. free(x);
  53. fclose(fp);
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement