Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <locale.h>
- #define L 8
- FILE * file,* file1,* file2;
- char filename[15]="null";
- char ars[n]="";
- int N=0;
- struct tab
- {
- char country[8];
- float y53;
- float y58;
- }f,f1;
- double sort()
- {
- }
- void write_file(void)
- { int N,i=0,ik;
- file=fopen("JOPA.dat","wb");
- if ((file == NULL))
- printf("\nОшибка создания файла");
- do
- {
- {
- printf("Enter country name:\n");
- scanf("%s",f.country);
- printf("Enter data of 53 y:\n");
- scanf("%f", &f.y53);
- printf("Enter data of 58 y:\n");
- scanf("%f", &f.y58);
- N++;
- printf("Желаете ввести данные? Нажмите 1\n");
- scanf("%d",&N);
- }
- fwrite(&f,sizeof(f),1,file);
- // из-за того что ввёл таб а не ф не было расчётов?
- } while(N==1);
- fclose(file);
- }
- void read_file()
- {
- int i=0,fv;
- file=fopen("JOPA.dat","rb");
- file1=fopen("Jora.dat","rb+wb");
- file2=fopen("Jojo.dat","rb+wb");
- if (file==NULL){printf("Не могу открыть файл\n");}
- if (file!=NULL){printf("Файл успешно открыт\n"); }
- fseek(file,0,SEEK_END);
- fv=ftell(file);
- n=fv;
- printf("|-----------------------------------------------|\n");
- printf("|Страна |1953 |1958 |\n");
- printf("|-----------------------------------------------|\n");
- while(i<fv)
- {
- fseek(file,i,SEEK_SET);
- fread(&f,sizeof(f),1,file);
- printf("|%15s|%15f|%15f|\n|-----------------------------------------------|\n",f.country,f.y53,f.y58);
- i += sizeof(f);
- if(f.y53<6)
- {
- fwrite(&f.y53,sizeof(f.y53),1,file1);
- fwrite(&f.country,sizeof(f.country),1,file1);
- }
- if(f.y58>4)
- {
- fwrite(&f1.y58,sizeof(f1.y58),1,file2);
- fwrite(&f1.country,sizeof(f1.country),1,file2);
- f1=f;
- /////////////
- }
- }
- fclose(file2);
- fclose(file1);
- fclose(file);
- }
- int main()
- {
- setlocale(LC_ALL,"RUS");
- int a,N;
- printf("Если хотите считать данные с файла, нажмите 1.\nЕсли нет, нажмите другую кнопку.\n");
- scanf("%d",&a);
- if(a==1){write_file();
- read_file();}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement