Advertisement
Zennoma

labafile

Dec 17th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. int main()
  6. {
  7.     int k = 0;
  8.     FILE* F;
  9.     char str[100];
  10.     char FILEName1[20];
  11.     char FILEName2[20];
  12.     puts("Enter first file name");
  13.     gets_s(FILEName1, 20);
  14.     fopen_s(&F, FILEName1, "w+b");
  15.     puts("Enter strings");
  16.  
  17.     while (gets_s(str, 100), strlen(str) != 0)
  18.     {
  19.         fputs(str,F);
  20.         fputs("\n", F);
  21.     }
  22.     rewind(F);
  23.     puts("FileF");
  24.     while (fgets(str, 100, F) > 0)
  25.     {
  26.         puts(str);
  27.        
  28.     }
  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 (fgets(str, 100, F) > 0)
  35.     {
  36.         if (k % 2 == 0)
  37.         {
  38.             fputs(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 (fgets(str, 100, 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