M
Mike Copeland
I'm looking for a way to parse some variables that are preceded by
the number of variables that follow. For example, I have the following
data:
5 3 4 2 5 1 Phase Count, Order
where the first value defines the number of values that follow (5). I
then want to place the five values in an array. The limits of my data
are 1 through 5; that is, there can be 1-5 values parsed and placed in
the array.
I am currently using a series of sscanfs in a select/case statement
(and I know it's UGLY!)...
switch(phaseCount) // parse phase order values (1-5)
{
case 1: sscanf(s24, "%d", &px[0]); break;
case 2: sscanf(s24, "%d%d", &px[0], &px[1]); break;
case 3: sscanf(s24, "%d%d%d", &px[0], &px[1], &px[2]); break;
case 4: sscanf(s24, "%d%d%d%d", &px[0], &px[1], &px[2], &px[3]);
break;
case 5: sscanf(s24, "%d%d%d%d%d", &px[0], &px[1], &px[2], &px[3],
&px[4]); break;
} // switch
Any thoughts? TIA
the number of variables that follow. For example, I have the following
data:
5 3 4 2 5 1 Phase Count, Order
where the first value defines the number of values that follow (5). I
then want to place the five values in an array. The limits of my data
are 1 through 5; that is, there can be 1-5 values parsed and placed in
the array.
I am currently using a series of sscanfs in a select/case statement
(and I know it's UGLY!)...
switch(phaseCount) // parse phase order values (1-5)
{
case 1: sscanf(s24, "%d", &px[0]); break;
case 2: sscanf(s24, "%d%d", &px[0], &px[1]); break;
case 3: sscanf(s24, "%d%d%d", &px[0], &px[1], &px[2]); break;
case 4: sscanf(s24, "%d%d%d%d", &px[0], &px[1], &px[2], &px[3]);
break;
case 5: sscanf(s24, "%d%d%d%d%d", &px[0], &px[1], &px[2], &px[3],
&px[4]); break;
} // switch
Any thoughts? TIA