Oh, I see. Hmm. Well, unfortunately, your current code only handles one range, because all you use is this:
Code:
if (i < range[0] || i> range[1])
With a loop, you could loop over the elements of range[] to handle more than one range.
But to remove single columns -- in that case, you'd either need to specify ranges that start and being at the same place -- inefficient -- or invent a new array and add some code to handle it. Which would be wasteful as well.
That's assuming you can even parse the numbers separately. strtok() will let you do this, you just have to instruct it to.
I'm actually a little confused about the parameters of your program. In your first example, you used this:
Code:
cutchar - 2 -6 < theFileName
But with your current code, because the first "-" is separated, it only works by fluke. It simply takes all numbers that it can see and uses them as ranges. If you were to add blacklisted columns in addition to ranges, you'd need to modify that code.
I'll assume your initial example was meant to be "-2 -6". What are you going to do with something like "-2,4 -6"? Is that columns 2 and 4 eliminated, and the range from 4 to 6 as well? It doesn't make sense. Sucky syntax if you ask me. Or wait: was it meant to be "-2-6"? That makes sense.
If that's the case, you'll want to look for parameters that start with a "-", parse a number from them, check the next character to see if it's a '-' or a ',' or the end of the string, and continue doing this until you actually get to the end of the string. sscanf(), or better yet, strtol() would really help you in doing this. For example:
Code:
int n;
char *begin, *p;
/* ... */
begin = argv[x]; /* set begin to the beginning of the string */
n = strtol(begin, &p, 0);
if(begin == p) { /* there was no number in begin */
break; /* we're done parsing this argument */
}
if(*p == ',') {
/* ... */
}
begin = p + 1;
/* loop around again and start parsing begin . . . */
Maybe that was just confusing. Any questions?