Advertisement
levartolona

C_PRG_LANG_EX_2.4

Jan 26th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. char *squeeze(char *s1, char *s2)
  7. {
  8.     int size = 0;
  9.     for(int i = 0; s1[i] != '\0'; i++, size++)
  10.         ;
  11.  
  12.     for(int i = 0; s1[i] != '\0'; i++)
  13.     {
  14.         for(int j = 0; s2[j] != '\0'; j++)
  15.         {
  16.             if (s1[i] == s2[j])
  17.             {
  18.                 for(int k = i; k < size; k++)
  19.                     s1[k] = s1[k + 1];
  20.  
  21.                 i--;
  22.                 size--;
  23.                 break;
  24.             }
  25.         }
  26.     }
  27.  
  28.     return s1;
  29. }
  30.  
  31. int main(void)
  32. {
  33.     char *str1 = malloc(sizeof(char) * 256);
  34.     char *str2 = malloc(sizeof(char) * 256);
  35.     strcpy(str1, "Mother washed the window");
  36.     strcpy(str2, "Mother washed the window");
  37.     printf("%s\n%s\n", str1, str2);
  38.     str1 = squeeze(str1, str2);
  39.     printf("%s\n", str1);
  40.     free(str1);
  41.     free(str2);
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement