Compare Two Strings without using strcmp


/*
Write a code block to compare two strings without using strcmp
*/

int compare(char a[], char b[])
{
int c = 0;

while( a[c] == b[c] )
{
if( a[c] == '\0' || b[c] == '\0' )
break;
c++;
}
if( a[c] == '\0' && b[c] == '\0' )
return 0;
else
return -1;
}

Post a Comment

0 Comments