Skip to content

Commit

Permalink
Added problem 2 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
robrighter committed May 4, 2012
1 parent cd4fc4c commit 15e14cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Binary file not shown.
30 changes: 30 additions & 0 deletions 02-compare-strings-ignoring-noise-char/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <string.h>

#define FALSE 0

int compareStrings(const char *str1, const char *str2, char noise){
while(str1[0] == noise) str1++;
while(str2[0] == noise) str2++;

if(str1[0] == '\0'){
return (str2[0] == '\0');
}
else if(str2[0] == '\0'){
return FALSE;
}
else if(str1[0] == str2[0]){
return compareStrings(++str1, ++str2, noise);
}
return FALSE;
}

int main(int argc, char *argv[]){
if(argc < 4){
fprintf(stdout,"Usage: compare-strings [string 1] [string 2] [noise character]\n");
return 1;
}

fprintf(stdout, compareStrings(argv[1],argv[2],argv[3][0]) ? "The strings are equal.\n":"The strings are NOT equal.\n");
return 0;
}

0 comments on commit 15e14cc

Please sign in to comment.