Your problem is that you don't detect the end of the string and therefore don't return zero if both strings ends before any difference is detected.
You can simply fix this by checking for this in the loop condition:
while( flag==0 && (string1[i] != 0 | string2[i] != 0 ) ) Note that both strings are checked because if only one is at the end the strings are not equal and the comparison inside the loop should detect that.
Please note that the character comparison might not yield the result that you might expect. For one it's not defined whether char is signed or unsigned so you should probably cast to unsigned char for comparison.
Perhaps a cleaner solution would be to return immediately when you detect the difference, that is instead of flag = -1 you return -1 directly. But that's more a matter of opinion.