Scanset

L

lezard

I can't find a good charset for my string.
The separator is ':' :-(

Look at this code

int main()
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64s[:]%64s[:]%64s[\n]", buf1, buf2, buf3);
printf("buf1: %s\n", buf1);
printf("buf2: %s\n", buf2);
printf("buf3: %s\n", buf3);
}

I would like to have tititi in buf1, tutu in buf2 and toto in buf3
But with this scanset It doesn't work. I have tried
"%64s%*[:]%64s%*[:]%64s%*[\n]" and It doesn't work too.

Could someone help me? :]
 
P

pete

lezard said:
I can't find a good charset for my string.
The separator is ':' :-(

Look at this code

int main()
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64s[:]%64s[:]%64s[\n]", buf1, buf2, buf3);
printf("buf1: %s\n", buf1);
printf("buf2: %s\n", buf2);
printf("buf3: %s\n", buf3);
}

I would like to have tititi in buf1, tutu in buf2 and toto in buf3
But with this scanset It doesn't work. I have tried
"%64s%*[:]%64s%*[:]%64s%*[\n]" and It doesn't work too.

Could someone help me? :]

int main(void)
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64[^:]%*[:]%64[^:]%*[:]%64[^\n]", buf1, buf2, buf3);
printf("buf1: %s\n", buf1);
printf("buf2: %s\n", buf2);
printf("buf3: %s\n", buf3);
return 0;
}
 
L

lezard

int main(void)
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64[^:]%*[:]%64[^:]%*[:]%64[^\n]", buf1, buf2, buf3);
printf("buf1: %s\n", buf1);
printf("buf2: %s\n", buf2);
printf("buf3: %s\n", buf3);
return 0;
}

Thx a lot Pete!
 
E

Eric Sosman

pete said:
lezard said:
I can't find a good charset for my string.
The separator is ':' :-(

Look at this code

int main()
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64s[:]%64s[:]%64s[\n]", buf1, buf2, buf3);
printf("buf1: %s\n", buf1);
printf("buf2: %s\n", buf2);
printf("buf3: %s\n", buf3);
}

I would like to have tititi in buf1, tutu in buf2 and toto in buf3
But with this scanset It doesn't work. I have tried
"%64s%*[:]%64s%*[:]%64s%*[\n]" and It doesn't work too.

Could someone help me? :]


int main(void)
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64[^:]%*[:]%64[^:]%*[:]%64[^\n]", buf1, buf2, buf3);

ITYM "63" for each "64". Also, the format can be
simplified a bit:

sscanf(str, "%63[^:]:%63[^:]:%63[^\n]", ...
 
P

Peter Nilsson

pete said:
...
int main(void)
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64[^:]%*[:]%64[^:]%*[:]%64[^\n]", buf1, buf2,
buf3);

Note you should check the return value of sscanf. For instance, the
string "a::c" will put "a" into buf1, and "c" into buf2, with sscanf
returning 2, leaving the contents of buf3 unspecified. You also have
an off by 1 error.

You can also simplify by matching the colons directly...

r = sscanf(str, "%63[^:\n]:%63[^:\n]:%63[^\n]", buf1, buf2, buf3);
 
P

pete

Eric said:
lezard said:
I can't find a good charset for my string.
The separator is ':' :-(

Look at this code

int main()
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64s[:]%64s[:]%64s[\n]", buf1, buf2, buf3);
printf("buf1: %s\n", buf1);
printf("buf2: %s\n", buf2);
printf("buf3: %s\n", buf3);
}

I would like to have tititi in buf1, tutu in buf2 and toto in buf3
But with this scanset It doesn't work. I have tried
"%64s%*[:]%64s%*[:]%64s%*[\n]" and It doesn't work too.

Could someone help me? :]


int main(void)
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64[^:]%*[:]%64[^:]%*[:]%64[^\n]",
buf1, buf2, buf3);

ITYM "63" for each "64".

I think so too.
Also, the format can be
simplified a bit:

sscanf(str, "%63[^:]:%63[^:]:%63[^\n]", ...

Thank you.
 
P

pete

Peter said:
...
int main(void)
{
char *str = "titititi:tutu:toto\n";
char buf1[64];
char buf2[64];
char buf3[64];

sscanf(str, "%64[^:]%*[:]%64[^:]%*[:]%64[^\n]", buf1, buf2,
buf3);

Note you should check the return value of sscanf. For instance, the
string "a::c" will put "a" into buf1, and "c" into buf2, with sscanf
returning 2, leaving the contents of buf3 unspecified. You also have
an off by 1 error.

You can also simplify by matching the colons directly...

r = sscanf(str, "%63[^:\n]:%63[^:\n]:%63[^\n]", buf1, buf2, buf3);

Thank you.
 
C

CBFalconer

lezard said:
.... snip ...
{
char *str = "titititi:tutu:toto\n";
.... snip ...

I would like to have tititi in buf1, tutu in buf2 and toto in buf3

Many people would like to see all titis in the buf. Those with
tutus are innately not in the buf, and I think toto would bark if
so confined. Meanwhile you are offending the prudes :)

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 
R

Richard Bos

CBFalconer said:
Many people would like to see all titis in the buf. Those with
tutus are innately not in the buf, and I think toto would bark if
so confined. Meanwhile you are offending the prudes :)

....which is always a good thing to do ;->

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top