nikitast

bilet_9 (Binary_Files)

Jan 19th, 2021 (edited)
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main()
  7. {
  8.     FILE* f;
  9.     char str[255];
  10.     f = fopen("BINARY.bin", "wb");
  11.     puts("Enter the sequence:");
  12.     gets_s(str);
  13.     fwrite(str, sizeof(str), 1, f);
  14.     fclose(f);
  15.     f = fopen("BINARY.bin", "rb");
  16.     fread(str, sizeof(str), 1, f);
  17.     puts("File:");
  18.     puts(str);
  19.     fclose(f);
  20.     char new_str[255];
  21.     int cnt = 0;
  22.     for (int i = 0; i < strlen(str); i++)
  23.     {
  24.         if ((int(str[i]) - 48) % 5 != 0)
  25.         {
  26.             new_str[cnt] = str[i];
  27.             cnt++;
  28.         }
  29.     }
  30.     new_str[cnt] = '\0';
  31.     f = fopen("BINARY.bin", "wb");
  32.     fwrite(new_str, sizeof(str), 1, f);
  33.     fclose(f);
  34.     f = fopen("BINARY.bin", "rb");
  35.     fread(str, sizeof(str), 1, f);
  36.     puts("Changed file:");
  37.     puts(str);
  38.     fclose(f);
  39.     return 0;
  40. }
Add Comment
Please, Sign In to add comment