Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main(int argc, char* argv[])
  5. {
  6.     char c;
  7.     int len_new = 0;
  8.     FILE *f1, *f2;
  9.     int len3, i = 0, f = 0;
  10.     long pos = 0;
  11.     while (argv[3][i] != '\0')
  12.     {
  13.         ++i;
  14.     }
  15.     len3 = i;
  16.     f1 = fopen(argv[1], "r");
  17.     f2 = fopen(argv[2], "w");
  18.     if ( (argc < 4) || (f1 == NULL) || (f2 == NULL) )
  19.     {
  20.         printf("Wrong input\n");
  21.         exit(1);
  22.     }
  23.     while ( (c = fgetc(f1)) != EOF)
  24.     {
  25.         f = 0;
  26.         if (c != argv[3][0])
  27.         {
  28.             fputc(c, f2);
  29.         }
  30.         if (c == argv[3][0])
  31.         {
  32.             pos=ftell(f1) - 1;
  33.             fseek(f1, -1, SEEK_CUR);
  34.             for (i = 0;i < len3; i++)
  35.             {
  36.                 c = fgetc(f1);
  37.                 if (c != argv[3][i])
  38.                 {
  39.                     f = 1;
  40.                     break;
  41.                 }
  42.             }
  43.             if (f == 0)
  44.             {
  45.                 for (int j = 0; j < strlen(argv[4]); j++)
  46.                     fputc(argv[4][j], f2);
  47.             }
  48.             if (f == 1)
  49.             {
  50.                 fseek(f1, -(i+1), SEEK_CUR);
  51.                 c = fgetc(f1);
  52.                 fputc(c, f2);
  53.             }
  54.            
  55.         }
  56.     }
  57.     fclose(f1);
  58.     fclose(f2);
  59.     return(1);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement