So the given task is to make a function that checks for any string if
- All 5 letters 'a', 'b', 'c', 'd', and 'e' are included (in any sequence) and
- The string 'abcde' is a substring of the given string. If 1 holds (but 2 does not), return 1. If both 1 and 2 holds, return 2. Otherwise, return 0.
Examples:
checkabcde(“someaxbxcxdxemm”) -> 1
checkabcde(“someOtherValue”) -> 0
checkabcde(“xyabcdeping”) -> 2
checkabcde(“someaxuxdxlxammabcde”) -> 2
In my approach I've been able to find that is the substring is "abcde" but unable to determine that the string contains 'a', 'b', 'c', 'd', 'e' in any sequence
int checkabcde(char str[]) {
char str2[] = {
'a',
'b',
'c',
'd',
'e'
};
char str3[5]; //to be filled with elements from str2 when found inconsecutive order
int i, z, x, f;
z = 0; //position for str3
f = 0; //flag for similarity comparison of str2 and str3
for (i = 0; i < strlen(str); i++) {
for (x = 0; x < strlen(str2); x++) {
if (str[i] == str2[x]) {
if ((str[i] == 'a') && (str[i + 1] == 'b') && (str[i + 2] == 'c') && (str[i + 3] == 'd') && (str[i + 4] == 'e')) {
return 2;
} else {
if (str3[z] != str[z - 1]) {
str3[z] = str2[x];
z++;
}
}
}
}
}
for (i = 0; i < 5; i++) {
for (x = 0; x < 5; x++) {
if (str2[i] == str3[x]) {
f++;
}
}
}
if (f == 5) {
return 1;
} else if (f1 == 0) {
return 0;
}
}
edit: pointers not allowed