acobzew

sem3-problem2

Apr 9th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #define N 100
  4.  
  5. void getstr(char s[]) {
  6.     char c;
  7.     int i = 0;
  8.     while((c = getchar()) != '\n')
  9.         s[i++] = c;
  10.     s[i] = '\0';
  11. }
  12.  
  13. char *filterChars(char s1[], char s2[]) {
  14.     static char ans[N];
  15.     int i = 0, j = 0, k = 0;
  16.     bool filter = false;
  17.     for (i = 0; s1[i] != '\0'; i++) {
  18.         for (j = 0; s2[j] != '\0'; j++) {
  19.             if (s1[i] == s2[j])
  20.                 filter = true;
  21.         }
  22.         if (!filter)
  23.             ans[k++] = s1[i];
  24.         filter = false;
  25.     }
  26.     return ans;
  27. }
  28.  
  29. int main() {
  30.     char s1[N], s2[N];
  31.     getstr(s1);
  32.     getstr(s2);
  33.     char *s3 = filterChars(s1, s2);
  34.     printf("%s", s3);
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment