Advertisement
tomasaccini

Untitled

Jul 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdbool.h>
  4.  
  5. int main(int argc, char* argv[]) {
  6.     char* A = argv[1];
  7.     char* B = argv[2];
  8.     char* C = argv[3];
  9.  
  10.     size_t A_len = strlen(A);
  11.     size_t B_len = strlen(B);
  12.     size_t C_len = strlen(C);
  13.  
  14.     for (size_t i = 0; i < A_len; i++){
  15.         bool reemplazo = true;
  16.         for (size_t j = 0; j < B_len; j++) {
  17.             if (A[i + j] != B[j]) {
  18.                 reemplazo = false;
  19.                 break;
  20.             }
  21.         }
  22.         if (reemplazo) {
  23.             printf("%s", C);
  24.             i += B_len - 1;
  25.         } else {
  26.             printf("%c", A[i]);
  27.         }
  28.     }
  29.     printf("\n");
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement