Code:
void main(){
char set[] = "1,3,5-7,9,11,23-27,30", currChar, *lowerRange = set, *upperRange = set;
int low, hi, i = 0;
do{
currChar = set[i]; // get the char before we destroy the original string
if(currChar == '-'){ // check if we need a pointer to second number
upperRange = &set[i] + 1; // point upper to next char
set[i] = 0; // end the lower range string
}
if(currChar == ',' || set[i + 1] == 0){ // check for comma or end of string
if(currChar == ',') set[i] = 0; // end the 'number string'
for(low = atoi(lowerRange), hi = atoi(upperRange); low <= hi; low++)
printf("%d, ", low);
lowerRange = upperRange = &set[i] + 1; // point lower/upper to next char
}
} while(set[++i] != 0);
}