On Wed, 5 Dec 2012 21:26:40 -0500 Rich Felker wrote: > > I'm getting the idea that that may actually work...in which case my > > last version is unneeded. > > Except, it breaks here: > > 00123 > > 001145 <-should be the lesser (the leading zeros) > > Yes, I was unaware of the leading-zero semantics when I wrote that. > See my revised email with a proposed algorithm. Which is almost exactly the same as the method below: > > OTOH, it could be done by recording the zero while walking up the chain: > > /*NOT tested*/ > > while (*l && *r && l[0]==r[0]){ > > if (l[0]='0'){ > > nozero=1; > > It can't set the flag unconditionally, only if the previous byte was > not a digit. Otherwise, non-leading zeros would break handling of > numeric differences. Fortunately for us, that appears to be incorrect: idunham@Caracal:~$ ./a.out jan012 jan0111 1 1 idunham@Caracal:~$ ./a.out jan0001 jan001 -1 -1 idunham@Caracal:~$ ./a.out 0001 001 -1 -1 idunham@Caracal:~$ ./a.out 001 0001 1 1 idunham@Caracal:~$ ./a.out 0012 00111 1 1 idunham@Caracal:~$ ./a.out 00012 00111 -1 -1 idunham@Caracal:~$ ./a.out 00120 00111 1 1 That's testing with the attached version. -- Isaac Dunham