Re: parsing a string into substring and integers
- From: Stan Milam <stmilam@xxxxxxxxxx>
- Date: Fri, 15 Sep 2006 02:09:22 GMT
Peter Nilsson wrote:
Ian Collins wrote:monkeys paw wrote:Hello all, what is the easiest way to parse the following
string into components?
If the input format is fixed, use strncpy, passing the start position
char state[3];
int number;
int calendar_year;
int main()
{
char *s = "CA200617456";
}
What would need to happen after the parse is this:
state= "CA"
number=17456
calendar_year=2006
and size of each field.
If you want to convert the number to integer, strtol and friends can help.
Or just let sscanf do all the work for you...
int r = sscanf(s, "%2s%4d%4d", state, &number, &calendar_year);
Thank you for doing his homework.
--
Regards,
Stan Milam
=============================================================
Charter Member of The Society for Mediocre Guitar Playing on
Expensive Instruments, Ltd.
=============================================================
.
- Follow-Ups:
- Re: parsing a string into substring and integers
- From: monkeys paw
- Re: parsing a string into substring and integers
- References:
- parsing a string into substring and integers
- From: monkeys paw
- Re: parsing a string into substring and integers
- From: Ian Collins
- Re: parsing a string into substring and integers
- From: Peter Nilsson
- parsing a string into substring and integers
- Prev by Date: Re: functionpointer prototype with void* : question
- Next by Date: Re: parsing a string into substring and integers
- Previous by thread: Re: parsing a string into substring and integers
- Next by thread: Re: parsing a string into substring and integers
- Index(es):
Relevant Pages
|