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
- struct tab
- {
- char country[8];
- float y53;
- float y58;
- }f[6];
- int main()
- {
- int i;
- setlocale(LC_ALL,"RUS");
- int a,N;
- long leng;
- FILE *ishodnik;
- FILE *copy;
- printf("Если хотите считать данные с файла, нажмите 1.\nЕсли нет, нажмите другую кнопку.\n");
- scanf("%d",&a);
- if (a==1)
- {
- ishodnik=fopen("Laba.txt","r");
- if (ishodnik==NULL)
- {
- printf("Не могу открыть файл\n");
- }
- if (ishodnik!=NULL)
- {
- printf("Файл успешно создан\n");
- }
- for(i=0;i<1;i++)
- {
- fread(f[i].country,1,L,ishodnik);
- fseek(ishodnik,1,SEEK_CUR);
- printf("%s",f[i].country);
- printf("%f",f[i].y53);
- }
- while(i<2)
- {
- printf("%s %f %f",f[i].country,f[i].y53,f[i].y58);
- i++;
- }
- fclose(ishodnik);
- }
- if(a==2)
- {
- copy=fopen("Laba1.txt","w");
- if(copy==NULL)
- {
- printf("Error: cannot open file");
- }
- do
- {
- printf("Enter data of 53 y:\n");
- scanf("%f", &f[i].y53);
- printf("Enter data of 58 y:\n");
- scanf("%f", &f[i].y58);
- printf("Enter country name:\n");
- scanf("%s",f[i].country);
- printf("Желаете ввести данные? Нажмите 1\n");
- scanf("%d",&N);
- printf("%s",f[i].country);
- printf("%f",f[i].y53);
- i++;
- }while(N==1);
- fwrite(&f,sizeof(struct tab),1,copy);
- fclose(copy);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement