-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy path2-4.c
More file actions
38 lines (30 loc) · 693 Bytes
/
2-4.c
File metadata and controls
38 lines (30 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Exercise 2-4. Write an alternative version of squeeze(s1,s2) that deletes
* each character in s1 that matches any character in the string s2.
*
* By Faisal Saadatmand
*/
#include <stdio.h>
#define MAXCHAR 1000
/* functions */
void squeeze(char [], char []);
void squeeze(char s1[], char s2[])
{
int i, j, k;
k = 0;
for (i = 0; s1[i] != '\0'; ++i) {
for (j = 0; s2[j] != '\0' && s1[i] != s2[j]; ++j)
;
if (s2[j] == '\0') /* match not found */
s1[k++] = s1[i];
}
s1[k] = '\0';
}
int main(void)
{
char string1[MAXCHAR] = { "clean* *this- *str*-ing *** ---" };
char string2[MAXCHAR] = { "*-" };
squeeze(string1, string2);
printf("%s\n", string1);
return 0;
}