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 AEROFLOT
- {
- char a[N];
- char punct[N];//пункт назначения
- char tip[N];//тип самолета
- unsigned int nom;//номер рейса
- };
- typedef struct AEROFLOT AEROFLOT;
- int main()
- {
- AEROFLOT *x,b;
- FILE *file;
- FILE *fp;
- int p;
- const int m=10;
- int i=0,f=0;// limit = 33;
- char limit [N];
- x=(AEROFLOT*)malloc(M*sizeof(AEROFLOT));
- file=fopen("AEROFLOT.txt","r");
- while ((fscanf(file,"%s%s%d",x[i].punct,x[i].tip,&x[i].nom))!= EOF)
- {
- printf("%s\t %s\t%d\n",x[i].punct,x[i].tip,x[i].nom);
- i++;
- }
- fclose(file);
- fp=fopen("AEROFLOT.dat","wb");
- fwrite(&m,sizeof(int),1,fp);
- for(i=0;i<M;i++)
- {
- fwrite(&x[i],sizeof(AEROFLOT),1,fp);
- }
- fclose(fp);
- fp=fopen("AEROFLOT.dat","rb");
- fread(&m,sizeof(int),1,fp);
- scanf("%d",&p);
- fseek(fp,p*sizeof(AEROFLOT),SEEK_CUR);
- fread(&b,sizeof(AEROFLOT),1,fp);
- printf("Информация о самолете:\n%s\t%s\t%u\n",b.punct,b.tip,b.nom);
- free(x);
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement