Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!linac!att!iuvax!ux1.cso.uiuc.edu!osiris.cso.uiuc.edu!gordon From: gordon@osiris.cso.uiuc.edu (John Gordon) Newsgroups: comp.lang.c Subject: Re: Comparing strings... Message-ID: <1990Oct13.190106.15615@ux1.cso.uiuc.edu> Date: 13 Oct 90 19:01:06 GMT References: <2205.271700c2@cc.nu.oz.au> Sender: news@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana Lines: 34 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@osiris.cso.uiuc.edu #include gordon@cerl.cecer.army.mil #include GEnie: j.gordon14