Comparing strings...
Al Dunbar
userAKDU at mts.ucs.UAlberta.CA
Thu Oct 18 14:27:05 AEST 1990
In article <10678.271ade27 at amherst.bitnet>, twpierce at amherst.bitnet (Tim Pierce) writes:
>In article <1990Oct13.190106.15615 at ux1.cso.uiuc.edu>,
>gordon at osiris.cso.uiuc.edu (John Gordon) writes:
>
<<<deletions>>>
>> 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)
>> }
>
>Correct me if I'm wrong here (being a C neophyte myself), but shouldn't you be
>using a while loop rather than a for loop? It looks to me as if this code will
>return only the relative sizes of the last characters in the string, not
>stopping once an inequality is hit. Or does the return() statement imply a
>break?
>
The return() statement (or just "return;") "implies a break"
in the same way that going outside implies that you have left
the room.
-------------------+-------------------------------------------
Al Dunbar |
Edmonton, Alberta | this space for rent
CANADA |
-------------------+-------------------------------------------
#! r
More information about the Comp.lang.c
mailing list