473,414 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Scanset

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? :]

--
Lezard

Nov 14 '05 #1
8 3371
lezard wrote:

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;
}

--
pete
Nov 14 '05 #2
> 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!
Nov 14 '05 #3
pete wrote:
lezard wrote:
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]", ...

--
Eric Sosman
es*****@acm-dot-org.invalid

Nov 14 '05 #4
pete wrote:
...
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);
printf("buf1: %s\n", buf1);
printf("buf2: %s\n", buf2);
printf("buf3: %s\n", buf3);
return 0;
}


--
Peter

Nov 14 '05 #5
Eric Sosman wrote:

pete wrote:
lezard wrote:
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.

--
pete
Nov 14 '05 #6
Peter Nilsson wrote:

pete wrote:
...
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.

--
pete
Nov 14 '05 #7
lezard wrote:
.... 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:
news:news.announce.newusers
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
Nov 14 '05 #8
CBFalconer <cb********@yahoo.com> wrote:
lezard wrote:
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 :-)


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

Richard
Nov 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ramprasad A Padmanabhan | last post by:
Hello all I want to read into a string an input from QUERY_STRING how do I ensure that scanf reads more chars into the string that it can hold eg { char* s1; char* data; long n;
7
by: Przemo Drochomirecki | last post by:
hi, SCANF is not well described in my books, i'd like to do this stuff: 1) read all numbers from a line, separated by #32 2) read all numbers from a line, separaed by ',' 3) read whole line ...
7
by: Allan Bruce | last post by:
If I have sscanf("FL:%s:%d:%s\n", lGuid, &lID, lFileName); and the last string contains spaces, e.g. my complete string "FL:1234ABCD:3:FileName With Spaces.txt\n" does sscanf just make...
2
by: Petros Makris | last post by:
(please forgive me i don't know how to find older messages if this is already answered) I am trying to understand why fscanf( fp, "%s=%s\n", str1, str2); doesn't work when I am trying to...
4
by: Cal Lidderdale | last post by:
My input line is i1,i2,i3,i4,i5,i6,i7,i8^,...i596,597, ... 14101,14102...NL/CR very long line of data - I only want the first 8 items and the delimiter between 8 & 9 is a carrot "^". The line...
15
by: AndrewD | last post by:
Hi, Using scanf, is it possible to detect input numbers where the decimal count is too large? eg. scanf("%19lg",&var);
8
by: regis | last post by:
Greetings, about scanf matching nonempty sequences using the "%" matches a nonempty sequence of anything except '-' "%" matches a nonempty sequence of anything except ']" matches a nonempty...
2
by: Bernard Liang | last post by:
In response, I have another question about the scanf family. After reading in a %d value, for instance, do they immediately wade through all subsequent whitespace until a non-whitespace character...
7
by: vamshi | last post by:
main() { char str; printf("Enter a string: "); scanf("%",str); printf("%",str); } Can some one help me with this code? when i tried to execute this..... it reads the string untill character
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.