Comparing strings...
John Gordon
gordon at osiris.cso.uiuc.edu
Sun Oct 14 05:01:06 AEST 1990
Hmmm... Well, here's what I came up with:
int compare_strings(char s1[], char s2[])
{
int i;
for(i = 0; s1[i] && s2[i]; i++)
{
if(s1[i] > s2[i])
return(S1_BIGGER);
else if(s1[i] < s2[i])
return(S2_BIGGER)
}
/* if we got to here, s1 and s2 are either equal or equal up to a NULL */
if(strlen(s1) > strlen(s2))
return(S1_BIGGER);
else if(strlen(s1) < strlen(s2))
return(S2_BIGGER);
else
return(EQUAL);
}
If there are stupid syntactical errors in the code, I apologize. I just
sat down and wrote it.
---
John Gordon
Internet: gordon at osiris.cso.uiuc.edu #include <disclaimer.h>
gordon at cerl.cecer.army.mil #include <clever_saying.h>
GEnie: j.gordon14
More information about the Comp.lang.c
mailing list