Advertisement
Underhing

Untitled

May 13th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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 AEROFLOT
  8. {
  9. char a[N];
  10. char punct[N];//пункт назначения
  11. char tip[N];//тип самолета
  12. unsigned int nom;//номер рейса
  13. };
  14. typedef struct AEROFLOT AEROFLOT;
  15.  
  16. int main()
  17. {
  18. AEROFLOT *x,b;
  19. FILE *file;
  20. FILE *fp;
  21. int p;
  22. const int m=10;
  23. int i=0,f=0;// limit = 33;
  24. char limit [N];
  25. x=(AEROFLOT*)malloc(M*sizeof(AEROFLOT));
  26.  
  27. file=fopen("AEROFLOT.txt","r");
  28. while ((fscanf(file,"%s%s%d",x[i].punct,x[i].tip,&x[i].nom))!= EOF)
  29. {
  30. printf("%s\t %s\t%d\n",x[i].punct,x[i].tip,x[i].nom);
  31. i++;
  32. }
  33. fclose(file);
  34.  
  35. fp=fopen("AEROFLOT.dat","wb");
  36. fwrite(&m,sizeof(int),1,fp);
  37. for(i=0;i<M;i++)
  38. {
  39. fwrite(&x[i],sizeof(AEROFLOT),1,fp);
  40. }
  41. fclose(fp);
  42. fp=fopen("AEROFLOT.dat","rb");
  43. fread(&m,sizeof(int),1,fp);
  44. scanf("%d",&p);
  45. fseek(fp,p*sizeof(AEROFLOT),SEEK_CUR);
  46. fread(&b,sizeof(AEROFLOT),1,fp);
  47. printf("Информация о самолете:\n%s\t%s\t%u\n",b.punct,b.tip,b.nom);
  48. free(x);
  49. fclose(fp);
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement