c - Skipping strings between separator with sscanf() -
I have some strings such as this:
1 | 36 9 01 | O | 173665.47 | 1996-01-02 | 5-take. Clerical # 000000951 | 0 | Sleeps among the nstructions.
I want to remove the field in the position of 0, 1, 3, 7 in this situation 1
, 36 901
, 173665.47
and 0
.
I have tried
sscanf (line, "% d |% d |% * C |% lf |% * |% * s |% * s |% D |% * s | ", and rec.order_key, and rec.cust_key, & rec.total_price, and rec.ship_priority); Printf ("% d% d% lf% d", rec.order_key, rec.cust_key, rec.total_price, rec.ship_priority);
Expect to get more
1 36 9 01 173665.470000 0
Instead of me
< Pre> 1 36 9 01 173665.470000 1
So I think I have done something wrong with skipping, but I can not understand it.
I understand that: sscanf ()
matches greed, so Leaving the string is too long.
Using sscanf (line, "% d |% d |% * c |% lf |% * [^ |] |% * [^ |] |% * [^ | ] |% D |% * [^ |] | ", & rec.order_key, & rec.cust_key, and Rick Rick, & rec.ship_priority);
Problem solved
Comments
Post a Comment