First of all I have to said that my brain is burned because of this question. I need to write a function that checks whether the 3rd parameter is a interleaved of 1st and 2nd parameter. I wrote it but when I run it, it gives me this error. "warning: implicit declaration of function ‘interleaved’" Here is my code:
void main()
{
char str1[100] = "ABC";
char str2[100] = "XYZ";
char str3[100] = "XAYZBC";
printf(interleaved(str1, str2, str3));
}
bool interleaved(char str1[], char str2[], char str3[])
{
int i = 0, j = 0, k = 0;
if (strlen(str1) + strlen(str2) != strlen(str3))
return false;
while (k < strlen(str3))
{
if (i < strlen(str1) && str1[i] == str3[k])
i++;
else if (j < strlen(str2) && str2[j] == str3[k])
j++;
else
return false;
k++;
}
if (!(i == strlen(str1) && j == strlen(str2) && k == strlen(str3)))
return false;
return true;
}
I found the faulty part and tried to fix it as follows:
void main()
{
char str1[100] = "ABC";
char str2[100] = "XYZ";
char str3[100] = "XAYZBC";
bool result = interleaved(str1[100], str2[100], str3[100]);
printf(result);
}
Can anyone help me please ?