Advertisement
Lustacho

Untitled

Dec 5th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 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. struct tab
  7. {
  8.     char country[8];
  9.     float y53;
  10.     float y58;
  11. }f[6];
  12. int main()
  13. {
  14.     int i;
  15.     setlocale(LC_ALL,"RUS");
  16.     int a,N;
  17.     long leng;
  18.     FILE *ishodnik;
  19.     FILE *copy;
  20.       printf("Если хотите считать данные с файла, нажмите 1.\nЕсли нет, нажмите другую кнопку.\n");
  21.           scanf("%d",&a);
  22.          if (a==1)
  23.          {
  24.              ishodnik=fopen("Laba.txt","r");
  25.               if (ishodnik==NULL)
  26.              {
  27.                  printf("Не могу открыть файл\n");
  28.              }
  29.               if (ishodnik!=NULL)
  30.              {
  31.                  printf("Файл успешно создан\n");
  32.              }
  33.              for(i=0;i<1;i++)
  34.                 {
  35.           fread(f[i].country,1,L,ishodnik);
  36.           fseek(ishodnik,1,SEEK_CUR);
  37.           printf("%s",f[i].country);
  38.           printf("%f",f[i].y53);
  39.                 }
  40.  
  41.             while(i<2)
  42.             {
  43.             printf("%s %f %f",f[i].country,f[i].y53,f[i].y58);
  44.             i++;
  45.             }
  46.         fclose(ishodnik);
  47.          }
  48.         if(a==2)
  49.         {
  50.             copy=fopen("Laba1.txt","w");
  51.             if(copy==NULL)
  52.             {
  53.                 printf("Error: cannot open file");
  54.             }
  55.         do
  56.             {
  57.              printf("Enter data of 53 y:\n");
  58.              scanf("%f", &f[i].y53);
  59.              printf("Enter data of 58 y:\n");
  60.              scanf("%f", &f[i].y58);
  61.              printf("Enter country name:\n");
  62.              scanf("%s",f[i].country);
  63.              printf("Желаете ввести данные? Нажмите 1\n");
  64.              scanf("%d",&N);
  65.           printf("%s",f[i].country);
  66.           printf("%f",f[i].y53);
  67.                        i++;
  68.             }while(N==1);
  69.             fwrite(&f,sizeof(struct tab),1,copy);
  70.             fclose(copy);
  71.         }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement