Parsing lists containing numeric ranges

Sean Legassick cuuee at
Fri Jul 20 00:50:33 AEST 1990

Does anyone know of a C routine that will expand strings containing
numbers and ranges into a list of strings, or will give you the
numbers one at a time.

e.g. A function 'expand_range(char *string, char *buffer);' which on
     being given a pointer to the string "1,3-6,9-11,15" would place in
     buffer the string "1,3,4,5,6,9,10,11,15" (perhaps also having
     an integer argument for size of buffer so that a spurious '9-9999'
     didn't corrupt all data memory!)

or   Two functions, 'int expand_range_start(char *str);' and 'int
     expand_range_next(char *str);' which would return the expanded
     list of numbers one at a time.

 SSSSSSS  K  K L         Sean Legassick,
S         K K  L                             "Allow me to introduce
 SSSSSSS  KK   L         CU, University         myself: I am the main
        S K K  L          of Warwick               dish of the day."
 SSSSSSS  K  K LLLLLLL                                 (D Adams)

More information about the Comp.lang.c mailing list