Algorithm help: Find a string in another string?
My friend gave me this question that he got on a job interview. You're trying to see if its possible for firstString to equal secondString by simply deleting characters in the firstString. You're not actually altering anything, just checking to see if its possible and then returning true or false. In this case, its possible and I have worked the logic out on paper but I'm stumped on translating it into code. Can anyone point me in the right direction?
Code:
#include<stdio.h>
#include<string.h>
void checkString(char firstString[], char secondString[]);
int main(){
char firstString[20] = "aaabababaaasdfg";
char secondString[20] = "absd";
checkString(firstString, secondString);
}
void checkString(char firstString[], char secondString[]){
int i,j;
for(j = 0; j < strlen(secondString); j++){
for(i = 0; i < strlen(firstString); i++){
if(secondString[j] != firstString[i]){
....
}
else{
....
}
}
}
}