| Author |
how to parse this string in C ?
|
|
| clustur@gmail.com 2006-12-25, 7:06 pm |
| Here is the type of string I am trying to parse (Linux/C is the
platform):
dcc ddddd ccc:ccc <random set of characters/numbers with different
delimeters>
where d is an integer and c is a character.
There are no angled brackets in the actual string.
Max length of the string can be up to 1800 bytes.
I can parse "dcc ddddd ccc:ccc " part using sscanf very easily. The
next part which is a
random set of any number of words with different delimeters like
spaces,etc is the hard
part to parse.
For eg.
2ef 32345 cdf:ert Testing [23] am not sure; yes or no? {YY}
sss
It's easy to parse the initial part: 2ef 32345 cdf:ert
How do I parse the remaining random part with no known pattern into
just one buffer?
i.e. I need "Testing [23] am not sure; yes or no? {YY} sss" part into
one buffer after the parse.
I would like to use some C library functions like sscanf instead of
scanning each character
in a for loop until you hit the NULL termination.
| |
| Chris McDonald 2006-12-25, 7:06 pm |
| clustur@gmail.com writes:
>For eg.
> 2ef 32345 cdf:ert Testing [23] am not sure; yes or no? {YY}
>sss
> It's easy to parse the initial part: 2ef 32345 cdf:ert
> How do I parse the remaining random part with no known pattern into
>just one buffer?
> i.e. I need "Testing [23] am not sure; yes or no? {YY} sss" part into
>one buffer after the parse.
If the remaining text has "no known pattern", how can you expect to
*parse* it? The best you cna achieve is to determine where is commences,
and copy it from there to your location.
--
Chris.
| |
| Bjorn Reese 2006-12-26, 8:06 am |
| clustur@gmail.com wrote:
> Here is the type of string I am trying to parse (Linux/C is the
> platform):
> dcc ddddd ccc:ccc <random set of characters/numbers with different
> delimeters>
[...]
> How do I parse the remaining random part with no known pattern into
> just one buffer?
> i.e. I need "Testing [23] am not sure; yes or no? {YY} sss" part into
> one buffer after the parse.
Use %[^\n] in the sscanf format string.
--
mail1dotstofanetdotdk
| |
| clustur@gmail.com 2006-12-26, 10:09 pm |
|
Bjorn Reese wrote:
> clustur@gmail.com wrote:
> [...]
>
> Use %[^\n] in the sscanf format string.
>
> --
Thanks. it worked..
|
|
|
|