Advertisement
Zennoma

lababin

Dec 17th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <windows.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #define _CRT_SECURE_NO_WARNINGS
  7.  
  8.  
  9. int main()
  10. {
  11.     int k = 0;
  12.     FILE* F;
  13.     char str[100];
  14.     char FILEName1[20];
  15.     char FILEName2[20];
  16.     puts("Enter first file name");
  17.     gets_s(FILEName1, 20);
  18.     fopen_s(&F, FILEName1, "w+b");
  19.     puts("Enter strings");
  20.  
  21. while (gets_s(str, 100), strlen(str) != 0)
  22.     {
  23.         fwrite(&str, 1, sizeof(str), F);
  24.     }
  25.     rewind(F);
  26.     puts("FileF");
  27.     while (fread(&str, 1, sizeof(str), F) > 0)
  28.         puts(str);
  29.     rewind(F);
  30.     FILE* G;
  31.     puts("Enter second file name");
  32.     gets_s(FILEName2, 20);
  33.     fopen_s(&G, FILEName2, "w+b");
  34.     while (fread(&str, 1, sizeof(str), F) > 0)
  35.     {
  36.         if (k % 2 == 0)
  37.         {
  38.             fwrite(&str, 1, sizeof(str), G);
  39.         }
  40.         k++;
  41.     }
  42.     fclose(F); fclose(G);
  43.     puts("Elements of file G");
  44.     fopen_s(&G, FILEName2, "r+b");
  45.     int num = 1;
  46.     while (fread(&str, 1, sizeof(str), G) > 0)
  47.     {
  48.         printf_s("string order %d     ", num);
  49.         puts(str);
  50.         num += 2;
  51.     }
  52.     fclose(G);
  53.     return(0);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement