| ??? 06/06/07 17:01 Modified: 06/06/07 17:17 Read: times |
#140325 - How about... Responding to: ???'s previous message |
/*
* s: pointer to string to parse
* values: array of ints to store results in
* count: number of ints to parse and store in array
*
* returns: 1: success, 0: failure (invalid character)
*
* NOTE: Does not handle negative numbers. Changing ints to
* unsigned ints will optimize multiplication further.
*/
int get_values(const char* s, int values[], unsigned int count)
{
int i, j, temp, value;
char c;
for(j = 0; j < count; j++)
{
value = 0;
for(i = 0; i < 4; i++)
{
c = *s;
if ( (c < '0') || (c > '9') ) return 0;
value <<= 1;
temp = value << 2;
value += temp + (c - '0');
s++;
}
values[j] = value;
}
return 1;
}
|



