![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 1
Rep Power: 0
![]() |
sscanf or vsscanf : want to scan a list of integers in c
Hi,
I want to scan from the following string all the hex numbers and populate an array of integers: 0x27 0x00 0x30 0x00 0x33 0x00 0x36 0x00 ... How can I do so? Doing sscanf with a long list of "%x %x ..... %x" will do it. But is there a better way such as a loop etc. Can someone please help. Thanks, Shake |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 4
![]() |
Here's a nifty solution.
![]() #include <stdio.h>
int main ( void )
{
char *v = "0 1 2 3 4 5 6 7 8 9";
int i, x, n;
for ( i = 0; sscanf ( v + i, "%d%n", &x, &n ) == 1; i += n )
printf("%d ", x);
printf("\n");
return 0;
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|