How can i compare 2 string using recursion...
If string1 is started with string2 then return 1
else return 0
(assume both of strings are in same case and valid.)
e.g. string1 = hello guy; string2 = hello; <<< return 1
string1 = hello guy; string2 = ello; <<< return 0;
here is my recursion segment... I tried many times but still headache... I have no idea...
Code:int compareStr(char string1[], char string2[]) { int s1Found, s2Found; if (string1 == NULL || string2 == NULL){ printf("NULL pointer !\n"); return -2; } else if (string1[0] == '\0' || string2[0] == '\0'){ return -1; printf("Empty String !\n"); } else{ return s1Found = 1 + compareStr(&(string1[1]), &(string2[1])); } }