Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char* argv[])
- {
- char c;
- int len_new = 0;
- FILE *f1, *f2;
- int len3, i = 0, f = 0;
- long pos = 0;
- while (argv[3][i] != '\0')
- {
- ++i;
- }
- len3 = i;
- f1 = fopen(argv[1], "r");
- f2 = fopen(argv[2], "w");
- if ( (argc < 4) || (f1 == NULL) || (f2 == NULL) )
- {
- printf("Wrong input\n");
- exit(1);
- }
- while ( (c = fgetc(f1)) != EOF)
- {
- f = 0;
- if (c != argv[3][0])
- {
- fputc(c, f2);
- }
- if (c == argv[3][0])
- {
- pos=ftell(f1) - 1;
- fseek(f1, -1, SEEK_CUR);
- for (i = 0;i < len3; i++)
- {
- c = fgetc(f1);
- if (c != argv[3][i])
- {
- f = 1;
- break;
- }
- }
- if (f == 0)
- {
- for (int j = 0; j < strlen(argv[4]); j++)
- fputc(argv[4][j], f2);
- }
- if (f == 1)
- {
- fseek(f1, -(i+1), SEEK_CUR);
- c = fgetc(f1);
- fputc(c, f2);
- }
- }
- }
- fclose(f1);
- fclose(f2);
- return(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement