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 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
> 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!
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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;
|
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
...
|
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...
|
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...
|
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...
|
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);
|
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...
|
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...
|
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
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |