Advertisement
Lustacho

Untitled

Dec 12th, 2018
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <locale.h>
  5. #define L 8
  6. FILE * file,* file1,* file2;
  7. char filename[15]="null";
  8. char ars[n]="";
  9. int N=0;
  10. struct tab
  11. {
  12.     char country[8];
  13.     float y53;
  14.     float y58;
  15. }f,f1;
  16. double sort()
  17.     {
  18.     }
  19. void write_file(void)
  20.     {   int N,i=0,ik;
  21.         file=fopen("JOPA.dat","wb");
  22.         if ((file == NULL))
  23.             printf("\nОшибка создания файла");
  24.             do
  25.             {
  26.              {
  27.                  printf("Enter country name:\n");
  28.                  scanf("%s",f.country);
  29.                  printf("Enter data of 53 y:\n");
  30.                  scanf("%f", &f.y53);
  31.                  printf("Enter data of 58 y:\n");
  32.                  scanf("%f", &f.y58);
  33.                     N++;
  34.                  printf("Желаете ввести данные? Нажмите 1\n");
  35.                  scanf("%d",&N);
  36.             }
  37.                 fwrite(&f,sizeof(f),1,file);
  38.                 // из-за того что ввёл таб а не ф не было расчётов?
  39.             } while(N==1);
  40.             fclose(file);
  41.  
  42.     }
  43. void read_file()
  44.     {
  45.         int i=0,fv;
  46.         file=fopen("JOPA.dat","rb");
  47.         file1=fopen("Jora.dat","rb+wb");
  48.         file2=fopen("Jojo.dat","rb+wb");
  49.         if (file==NULL){printf("Не могу открыть файл\n");}
  50.         if (file!=NULL){printf("Файл успешно открыт\n"); }
  51.         fseek(file,0,SEEK_END);
  52.         fv=ftell(file);
  53.         n=fv;
  54.         printf("|-----------------------------------------------|\n");
  55.         printf("|Страна         |1953           |1958           |\n");
  56.         printf("|-----------------------------------------------|\n");
  57.         while(i<fv)
  58.         {
  59.             fseek(file,i,SEEK_SET);
  60.             fread(&f,sizeof(f),1,file);
  61.             printf("|%15s|%15f|%15f|\n|-----------------------------------------------|\n",f.country,f.y53,f.y58);
  62.             i += sizeof(f);
  63.              if(f.y53<6)
  64.        {
  65.                fwrite(&f.y53,sizeof(f.y53),1,file1);
  66.                fwrite(&f.country,sizeof(f.country),1,file1);
  67.                
  68.        }
  69.        if(f.y58>4)
  70.                  {
  71.                     fwrite(&f1.y58,sizeof(f1.y58),1,file2);
  72.                     fwrite(&f1.country,sizeof(f1.country),1,file2);
  73.                     f1=f;
  74.                     /////////////
  75.                    
  76.                    
  77.                  }
  78.        
  79.                
  80.         }
  81.         fclose(file2);
  82.         fclose(file1);
  83.         fclose(file);
  84.     }
  85. int main()
  86.     {
  87.           setlocale(LC_ALL,"RUS");
  88.           int a,N;
  89.           printf("Если хотите считать данные с файла, нажмите 1.\nЕсли нет, нажмите другую кнопку.\n");
  90.           scanf("%d",&a);
  91.           if(a==1){write_file();
  92.           read_file();}
  93.  
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement