Friday, 17 February 2012

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;
}

No comments:

Post a Comment