Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created January 9, 2016 13:54
Show Gist options
  • Save krysseltillada/82ec225328dc02f833de to your computer and use it in GitHub Desktop.
Save krysseltillada/82ec225328dc02f833de to your computer and use it in GitHub Desktop.
exercise 2-4 (the c programming language 2nd ed)
#include <stdio.h>
size_t getlen (char arr[])
{
int sz = 0;
for (; arr[sz] != '\0'; ++sz);
return sz;
}
void printStr (char arr[])
{
int i = 0;
for (; arr[i] != '\0'; ++i)
putchar (arr[i]);
}
void squeeze (char str[], char str2[])
{
int strCount1, strCount2 = 0, ind = 0;
for (strCount1 = 0; str[strCount1] != '\0'; ++strCount1) {
for (strCount2 = 0; str2[strCount2] != '\0'; ++strCount2) {
if (str[strCount1] == str2[strCount2])
break;
if (strCount2 == getlen(str2) - 1) {
str[ind++] = str[strCount1];
break;
}
}
}
str[ind] = '\0';
}
int main ()
{
char str1[] = "www.facebook.com";
char str2[] = "kwm";
squeeze(str1, str2);
printStr(str1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment