Skip to content

Instantly share code, notes, and snippets.

@gotjon05
Last active September 4, 2019 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotjon05/365b985e8ee65e156f6e2c12fa2fe557 to your computer and use it in GitHub Desktop.
Save gotjon05/365b985e8ee65e156f6e2c12fa2fe557 to your computer and use it in GitHub Desktop.
write an alternate version of squeeze (s1, s2) that deletes each character in s1 that matches any character in string s2
#include <stdio.h>
int main()
{
char s1[] = {"The course of true love never did run smooth"};
char s2[] = {'o', 'u', '\0'};
squeeze(s1, s2);
}
void squeeze(char s1[], char s2[])
{
int i, k, j;
k = j = 0;
for(i = 0; s1[i] != '\0'; i++){
if(s1[i] != s2[k++]){
s1[j++] = s1[i];
}
s2[k] = '\0';
}
printf("%s", s1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment