Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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.
- */
- #include <stdio.h>
- int squeeze(char *s1, const char* s2) {
- int i, j;
- int k = 0;
- for (i = 0; s1[i] ; i++) {
- for (j = 0; s2[j]; j++) {
- if (s1[i] == s2[j]) {
- break;
- }
- }
- if (!s2[j])
- s1[k++] = s1[i];
- }
- s1[k] = '\0';
- }
- int any(char *s1, const char* s2) {
- int i, j;
- for (i = 0; s1[i]; i++) {
- for (j = 0; s2[j]; j++) {
- if (s1[i] == s2[j]) {
- return i;
- }
- }
- }
- return -1;
- }
- int
- main(int argc, char** argv) {
- printf ("any(%s,%s) = %d\n", argv[1], argv[2], any(argv[1], argv[2]));
- squeeze(argv[1], argv[2]);
- printf ("squeeze = %s\n", argv[1]);
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment