Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define M 10
- #define N 33
- struct MAGAZIN
- {
- char a[N];
- char name[N];//пункт назначения
- char shop[N];//тип самолета
- unsigned int price;//номер рейса
- };
- typedef struct MAGAZIN MAGAZIN;
- int main()
- {
- MAGAZIN *x,b;
- FILE *file;
- FILE *fp;
- int p;
- const int m=10;
- int i=0,f=0;// limit = 33;
- char limit [N];
- x=(MAGAZIN*)malloc(M*sizeof(MAGAZIN));
- file=fopen("MAGAZIN.txt","r");
- printf ("\033[1;33mПРОГРАММА ДЛЯ ПОИСКА ТОВАРА В МАГАЗИНАХ\033[0m\n");
- printf("---{СТРУКТУРА}---\n");
- printf("Магазин: Товар: Цена:\n");
- while ((fscanf(file,"%s%s%d",x[i].name,x[i].shop,&x[i].price))!= EOF)
- {
- printf("%s\t %s\t%d\n",x[i].name,x[i].shop,x[i].price);
- i++;
- }
- fclose(file);
- fp=fopen("MAGAZIN.dat","wb");
- fwrite(&m,sizeof(int),1,fp);
- for(i=0;i<M;i++)
- {
- fwrite(&x[i],sizeof(MAGAZIN),1,fp);
- }
- fclose(fp);
- fp=fopen("MAGAZIN.dat","rb");
- fread(&m,sizeof(int),1,fp);
- scanf("%d",&p);
- fseek(fp,p*sizeof(MAGAZIN),SEEK_CUR);
- fread(&b,sizeof(MAGAZIN),1,fp);
- printf("Информация о самолете:\n%s\t%s\t%u\n",b.name,b.shop,b.price);
- free(x);
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement