If there's less than ten or so ports...I would do something like this, and I'm hoping you're not asking for homework help:
Code:
register int8_t num_ports = 10;
register int8_t c;
int *p = calloc(1, num_ports * sizeof(int));
p[0] = 333; /* just assign your ports, w/e */
p[3] = 56565;
p[4] = 1000;
p[5] = 100000;
p[6] = 61;
p[9] = 3;
p[num_ports] = 1; /* using 1 as an escape character, but you won't use port 1, right...? */
for (c = 0; c < num_ports; c++) {
while ( *p == 0) {
p++;
}
if (*p == 1) break;
/* bind your port w/e */
*p = 0;
}