Skip to content

Instantly share code, notes, and snippets.

@Learath2
Last active August 29, 2015 14:04
Show Gist options
  • Save Learath2/28589acbb193f920b54c to your computer and use it in GitHub Desktop.
Save Learath2/28589acbb193f920b54c to your computer and use it in GitHub Desktop.
K&R2 Exercise 2-4
/*K&R2 Exercise 2-4 "squeeze"*/
#include <stdio.h>
void squeeze(char[], char[]);
int main()
{
char s1[100] = "Test Mest Kest Sest Vest Mest";
char s2[10] = "sM";
printf("%s\n", s1);
squeeze(s1, s2);
printf("%s\n", s1);
}
void squeeze(char s1[], char s2[])
{
int i, j, n;
for(i = 0; s2[i] != '\0'; i++){
for(j = n = 0; s1[j] != '\0'; j++)
if(s1[j] != s2[i])
s1[n++] = s1[j];
s1[n] = '\0';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment