Skip to content

Instantly share code, notes, and snippets.

@thisiswei
Last active August 29, 2015 14:00
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 thisiswei/11052956 to your computer and use it in GitHub Desktop.
Save thisiswei/11052956 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
char* CensorString1(char t[], char r[]) {
char *newT;
int i, j, k, occured;
i = j = k = 0;
for (i = 0; t[i] != '\0'; i++){
occured = 0;
for (j = 0; r[j] != '\0'; j++) {
if (t[i] == r[j]) {
occured = 1;
}
}
if (!occured)
newT[k++] = t[i];
}
return newT;
}
void CensorString2(char t[], char r[]) {
int i, j, k, occured;
i = j = k = 0;
for (i = 0; t[i] != '\0'; i++){
occured = 0;
for (j = 0; r[j] != '\0'; j++) {
if (t[i] == r[j]) {
occured = 1;
}
}
if (!occured) {
t[k] = t[i];
k ++;
}
}
t[k] = '\0';
}
int main() {
char *t, *r;
t = "stanford university";
r = "nt";
char *newS;
newS = CensorString1(t, r);
puts(newS);
puts(t);
CensorString2(t, r);
puts(t);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment