#include<stdio.h>
#include<string.h>
int main (int argc, char* argv [])
{
int x, y, z;
int contained = 0;
int count =0;
int lenStr2 = 0; int i =0;
char str1[100];
strcpy(str1, argv[1]);
char str2[100];
strcpy(str2, argv[2]);
// counts the # of chars in Str2 - excludes null chracter
while (str2[i] != 0){
lenStr2++;
*(str2+i);
i++;
}
for(x=0; str1[x] != 0; x++){ //iterates through string 1
if (contained != 1){
if (str1[x] == str2[0]){ // if string1 == str2 first letter
for (y=0; str2[y] != 0; y++){ //iterates through str2
if ( str1[x] == str2[y]){
count++; //if letters match, add count
x++;
if( count == lenStr2){ //if the count equals to the len of str 2
contained = 1;
break;
}
}else{ //if the enxt chars dont match
break;
}
}
}
}else{
break;
}
}
// prints true or false statement
if (contained ==1){
printf("%s\n", "true");
} else {
printf("%s\n", "false");
}
return 0;
}
No comments:
Post a Comment